dotnet / dotnet/machinelearning

Dataframe.LoadCsv() throwing exception

Open
#6,773 0 comments 0 reactions 0 assignees View on GitHub
area-DataFrame untriaged
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

**System Information (please complete the following information):**
- OS & Version: Windows 10 Pro
- Microsfot.Data.Analysis: v0.22.1
- .NET Version: .NET 6.0

**Describe the bug**
I am having the same problem as reported on #5647. The input is the same since I created a csv file with same text and the exception thrown when running the code below is also the same.

```
System.FormatException
HResult=0x80131537
Message=Line 1 has less columns than expected
Source=Microsoft.Data.Analysis
StackTrace:
at Microsoft.Data.Analysis.DataFrame.GuessKind(Int32 col, List`1 read)
at Microsoft.Data.Analysis.DataFrame.ReadCsvLinesIntoDataFrame(WrappedStreamReaderOrStringReader wrappedReader, Char separator, Boolean header, String[] columnNames, Type[] dataTypes, Int64 numberOfRowsToRead, Int32 guessRows, Boolean addIndexColumn)
at Microsoft.Data.Analysis.DataFrame.LoadCsv(String filename, Char separator, Boolean header, String[] columnNames, Type[] dataTypes, Int32 numRows, Int32 guessRows, Boolean addIndexColumn, Encoding encoding)
at KeynotesPackagesTest.DataAnalysis.OpenCsvAndExportData(String csvFilePath, String textFile) in C:\Users\\source\repos\KeynotesPackagesTest\KeynotesPackagesTest\DataAnalysis.cs:line 102
at Program.$(String[] args) in C:\Users\\source\repos\KeynotesPackagesTest\KeynotesPackagesTest\Program.cs:line 35
```

**Expected behavior**
Reading the .csv file without issues

**Code**

```

public static void OpenCsvAndExportData(string csvFilePath, string textFile)
{
var data = DataFrame.LoadCsv(csvFilePath, separator: ',');
```

And then I cal the method from Program.cs
I hope I am not overseeing something basic since I am very new to the c# language.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.