1

I have a CSV file that I am trying to read through with the pandas module in python..(i am coding in Ubuntu).

pd.read_csv("filename.csv",skiprows=2)

I want to skip two rows so I am using skiprows argument here. (The file named filename.csv is created through a C program.) The problem which I am facing is that when I try to read the file directly then I am getting an IndexError as follows:

IndexError: index 0 is out of bounds for axis 0 with size 0

and one warning as

FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
res_values = method(rvalues)

But at the same time if I open my CSV file and just save it without doing any editing in it..my error gets resolved. So for every time, I need to read my CSV file I need to open it once through Libre Office(in Ubuntu) and save that file using ctrl+s and further in the option save as CSV text. Then, my program read it without any errors. But on not saving, it produces the above-mentioned error. Please help me with this issue. Thanks in Advance.

1
  • A csv file is a text file. Show its first lines before processing it through LibreOffice and after. The reason should be more visible... Commented May 29, 2020 at 7:13

2 Answers 2

1

I think it is about the format of csv file when exporting. Because of after open csv and save it, it gets the correct format. Check the file with notepad++ to correct the delimiter of csv file.

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

Comments

0

This is an IndexError in python, which means that we're trying to access an index that isn't there. I wrote is a very simple example to understand this error. Here I try to assign any value to some index.

import numpy as np

arr = np.array([], dtype=np.int64) 
print(arr.shape)
arr[0] = 23   

enter image description here

It might be There were a few instances of empty data frames that were causing the error. If you have numeric and non-numeric data in your index column. Then numpy gets confused when it tries to check whether the index is ordered.

For Solution:

df = pd.read_csv('your_file.tsv', sep='\t', header=0) 
df.set_index(['0'], inplace=True)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.