Home > Software design >  How to read a csv file using pandas in Python?
How to read a csv file using pandas in Python?

Time:01-24

I'm trying to read the following csv file https://storage.googleapis.com/play_public/supported_devices.csv using pandas:

android_data = pandas.read_csv("https://storage.googleapis.com/play_public/supported_devices.csv", sep = "delimiter", encoding = "ISO-8859-1", engine = "python")
print(android_data.head(10))

but the file is not parsed well, meaning the dataframe contains the following data:

   ÿþRetail Branding,Marketing Name,Device,Model
0                                                                                        
1  ,,AD681H,Smartfren Andr...                                      
2                                                                                        
3                        ,,FJL21,FJL21                                      
4                                                                                        
5  ,,hws7721g,MediaPad 7 Y...                                      
6                                                                                        
7  1&1,1&1 Puck,diw362_1u1...                                      
8                                                                                        
9  1&1,1&1 TV Box,diw387_1...  

Why there are the even lines empty and why each odd line contains all row data under "Retail Branding" column?

CodePudding user response:

The file is actually encoded as UTF-16LE, and sep should be ",", not "delimiter". The following worked for me:

url = "https://storage.googleapis.com/play_public/supported_devices.csv"
android_data = pandas.read_csv(url, sep=",", encoding="UTF-16LE", engine="c")
  •  Tags:  
  • Related