IndexError: understanding too many indications for array

Asked 2 years ago, Updated 2 years ago, 48 views

I don't know why this error occurs.
The code I wrote looks like this.

>>>if__name__=="_main__":
...         data1 = np.genfromtxt('./ozon_sheet.csv')
...         x1 = data1 [:,1]
... 
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
IndexError: too many indications for array
>> 

I look forward to hearing from you.

python numpy

2022-09-30 11:52

1 Answers

The csv file is separated by a comma, so you can specify a comma in the delimiter.

data1=np.genfromtxt('./ozon_sheet.csv', delimiter=',')

If not specified, spaces and tabs will be used as delimiters, so csv will not load as expected.

Incidentally, the first row of the csv file is the header, using names if you want to use it as a column name, or skip_header if you just want to skip it.

data1=np.genfromtxt('./ozon_sheet.csv', delimiter=',',',names=True)
data1 = np.genfromtxt('./ozon_sheet.csv', delimiter=',', skip_header=1)


2022-09-30 11:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.