-1
data = pd.open_csv('file.csv')
print(data)

gives this result:

    ��B  Unnamed: 1  Unnamed: 2  Unnamed: 3
0    NaN         NaN         NaN         NaN
1    NaN         NaN         NaN         NaN
2    NaN         NaN         NaN         NaN
3    NaN         NaN         NaN         NaN
4    NaN         NaN         NaN         NaN
....

Why is this happening? Why is everything NaN?

Georgy
  • 12,464
  • 7
  • 65
  • 73
usera
  • 23
  • 4
  • What is the content in `file.csv`? – Alejandro Alcalde Jul 03 '19 at 10:24
  • try also with read_csv() – Matteo Peluso Jul 03 '19 at 10:29
  • The content is my bank transactions: date, name, sum and currency – usera Jul 03 '19 at 10:56
  • Since the problem is one of file import, the data file is part of what we need to [reproduce the problem](https://stackoverflow.com/help/reprex). Please provide some data that causes the undesirable behavior (mock up that data if you cannot share the actual file or if it is too long), not a human summary of what is inside. – Leporello Jul 03 '19 at 12:28
  • Does this answer your question? [Get pandas.read\_csv to read empty values as empty string instead of nan](https://stackoverflow.com/questions/10867028/get-pandas-read-csv-to-read-empty-values-as-empty-string-instead-of-nan) – dank8 Mar 03 '23 at 02:27

2 Answers2

0

Common fixes would be either you have to mention your delimiter

df = pd.read_csv("file.csv", sep = "\t")

or you have to check the text encoding type of your file. If it is not UTF type then encode it to a UTF type, save and try opening then.

0

Maybe it's an encoding issue? Are you sure the files has been encoded in the standard utf-8.

In any case, try to read your csv using:

df = pd.read_csv('file.csv', header = 0, engine = 'python')

Hope this helps :)

Joe
  • 879
  • 2
  • 6
  • 15