+ 6

python csv error

I want to read a csv file using pandas but it is showing error . I am not getting that what is problem in this . Code \/ https://code.sololearn.com/cnV2EUntHHuY/?ref=app CSV file \/ https://www.dropbox.com/s/lf5xg0wr9akwc9r/Periodic%20Table%20of%20Elements.csv?dl=0

27th May 2020, 4:33 PM
Ayush Kumar
Ayush Kumar - avatar
5 Respostas
+ 9
Hi, i downloaded the file to check. In dropbox it shows correctlly the content! But after downlod the file looks damaged. But it is not! The file is a native excel file, even if it has the extension *.csv. I renamed it, so it was possible to open the file in libre office, and it looks ok. I am sure that this is the reason for your problem. If you try to load a real csv file, it should work.
27th May 2020, 5:48 PM
Lothar
Lothar - avatar
+ 6
I just remembered that there is a possibility to read an excel file directly with pandas. It should be like: import pandas as pd file1 = pd.read_excel(<path with file name>) file1.to_csv(<path with file name>) I am not able to check if it works properly. May be you can check the pandas documentation.
27th May 2020, 7:51 PM
Lothar
Lothar - avatar
+ 3
You should inspect the file, there has to be something wrong with it. Read_csv infers the number of columns from rhe first row and assumes that it stays constant throughout the file which is apparently not true here. This is why the parser is having problems.
27th May 2020, 4:56 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
Hay Kuba Siekierzyński had you gone through CSV file . I had attached a link for it . I think there is no such ishu. Of course there are some weeknd places. Then they should contain nan by default. Have a look to CSV file . I
27th May 2020, 5:02 PM
Ayush Kumar
Ayush Kumar - avatar