1

I am reading a csv with

numpy.genfromtxt(csv_name, delimiter=',') 

but I am unable to do so because my csv contains different no of columns for each row.

o/p:

ValueError: Some errors were detected
 Line #2 (got 8 columns instead of 7)
 Line #3 (got 8 columns instead of 7)
 Line #4 (got 8 columns instead of 7)
 Line #6 (got 8 columns instead of 7)
 Line #7 (got 5 columns instead of 7)
 Line #8 (got 5 columns instead of 7)
 Line #9 (got 5 columns instead of 7)
 Line #10 (got 5 columns instead of 7)

Is is possible to do with numpy?

2

2 Answers 2

1

https://docs.scipy.org/doc/numpy/reference/generated/numpy.genfromtxt.html, you can do it using the filling_values argument of genfromtxt.

Otherwise, you could use this answer: Python: How to read a data file with uneven number of columns

Sign up to request clarification or add additional context in comments.

Comments

0

If it is ok to restrict the data that is read to the common number of columns across all rows, you can use usecols to explicitly select the columns to read, e.g.:

numpy.genfromtxt(csv_name, delimiter=',', usecols=range(4))

2 Comments

This is probably related to the actual data in your CSV-file. A sample of the data is needed to clarify this.
You may need to specify the dtype

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.