1

Currently I am getting the below Error and I am tried out the below posts:

  1. Solution 1
  2. Solution 2

But I am not able to get the error resolved. My python code is as below:

import pandas as pd
testdata = pd.read_csv(file_name, header=None, delim_whitespace=True)

I tried to print the value in testdata but it doesn't show any output.

The following is my csvfile:

Screenshot

Franckentien
  • 324
  • 6
  • 21
Haritha
  • 167
  • 2
  • 4
  • 16

3 Answers3

0

Firstly, declare your filename inside testdata as a string, and make sure it is either in the local directory, or that you have the correct filepath.

import pandas as pd
testdata = pd.read_csv("filename.csv", header=None, delim_whitespace=True)

If that does not work, post some information about the environment you are using.

ajsp
  • 2,512
  • 22
  • 34
0

First, you probably don't need header=None as you seem to have headers in the file. Also try removing the blank line between the headers and the first line of data. Check and double check your file name.

blissweb
  • 3,037
  • 3
  • 22
  • 33
0

I tried your code as is with an example file, then I got this error:

Error

I then added an additional "header" to the file above the 3rd column of data:

Updated File

This successfully reads the CSV into a pandas df:

Output Dataframe

So you need to add a header to the last column.

SwanXI
  • 11
  • 4
  • Please read [Why should I not upload images of code/data/errors?](https://meta.stackoverflow.com/q/285551/354577) Instead, format code as a [code block]. The easiest way to do this is to paste the code as text directly into your question, then select it and click the code block button. – ChrisGPT was on strike Aug 31 '23 at 19:50