Import a CSV file into pandas into the pandas framework

I have a CSV file taken from an SQL dump that looks like this (the first few lines using head file.csv from the terminal):

??AANAT,AANAT1576,4 AANAT,AANAT1704,1 AAP,AAP-D-12-00691,8 AAP,AAP-D-12-00834,3 

When I use the pd.read_csv ('file.csv') command, I get the error “ValueError: No columns to parse from file”.

Any ideas on how to import a CSV file into a table and avoid the error?

QUESTION DEVELOPMENT (after Ed comment)

I tried header = None, skiprows = 1 to avoid ?? (which appear when using the head command from the terminal).

Path to extract the file http://goo.gl/jyYlIK

+7
python pandas csv
source share
1 answer

So, the symbols ?? which you see are actually non-printable characters which, after looking at your source csv file with a hex editor, show that they are actually utf-16 little endian \FFEE , which is an order byte.

So, all you have to do is pass this as an encoding type, and it reads in order:

 In [46]: df = pd.read_csv('otherfile.csv', encoding='utf-16', header=None) df Out[46]: 0 1 2 0 AANAT AANAT1576 4 1 AANAT AANAT1704 1 2 AAP AAP-D-12-00691 8 3 AAP AAP-D-12-00834 3 4 AAP AAP-D-13-00215 10 5 AAP AAP-D-13-00270 7 6 AAP AAP-D-13-00435 5 7 AAP AAP-D-13-00498 4 8 AAP AAP-D-13-00530 0 9 AAP AAP-D-13-00747 3 
+11
source share

All Articles