I need to create a pandas.DataFrame from a csv file. For that I am using the method pandas.csv_reader(...). The problem with this file is that one or more columns contain commas within the values (I don't control the file format). I been trying to implement the solution from this question but I get the following error:
pandas.errors.EmptyDataError: No columns to parse from file For some reason after implementing this solution the csv file I tried fixing is blank.
Here is the code I am using:
# fix csv file with open ("/Users/username/works/test.csv",'rb') as f,\ open("/Users/username/works/test.csv",'wb') as g: writer = csv.writer(g, delimiter=',') for line in f: row = line.split(',', 4) writer.writerow(row) # Manipulate csv file data = pd.read_csv(os.path.expanduser\ ("/Users/username/works/test.csv"),error_bad_lines=False) Any ideas?
Data overview:
Id0 Id 1 Id 2 Country Company Title Email 23 123 456 AR name cargador [email protected] 24 123 456 AR name Executive assistant [email protected] 25 123 456 AR name Asistente Administrativo [email protected] 26 123 456 AR name Atención al cliente vía telefónica vía online [email protected] 39 123 456 AR name Asesor de ventas [email protected] 40 123 456 AR name inc. International company representative [email protected] 41 123 456 AR name Vendedor de campo [email protected] 42 123 456 AR name PUBLICIDAD ATENCIÓN AL CLIENTE [email protected] 43 123 456 AR name Asistente de Marketing [email protected] 44 123 456 AR name SOLDADOR [email protected] 217 123 456 AR name Se requiere vendedores Loja Quevedo Guayas) [email protected] 218 123 456 AR name Ing. Civil recién graduado Yaruquí [email protected] 219 123 456 AR name ayudantes enfermeria [email protected] 220 123 456 AR name Trip Leader for International Youth Exchange [email protected] 221 123 456 AR name COUNTRY MANAGER / DIRECTOR COMERCIAL [email protected] 250 123 456 AR name Ayudante de Pasteleria [email protected] Asesor [email protected] [email protected] Pre-parsed CSV:
#,Id 1,Id 2,Country,Company,Title,Email,,,, 23,123,456,AR,name,cargador,[email protected],,,, 24,123,456,AR,name,Executive assistant,[email protected],,,, 25,123,456,AR,name,Asistente Administrativo,[email protected],,,, 26,123,456,AR,name,Atención al cliente vía telefónica , vía online,[email protected],,, 39,123,456,AR,name,Asesor de ventas,[email protected],,,, 40,123,456,AR,name, inc.,International company representative,[email protected],,, 41,123,456,AR,name,Vendedor de campo,[email protected],,,, 42,123,456,AR,name,PUBLICIDAD, ATENCIÓN AL CLIENTE,[email protected],,, 43,123,456,AR,name,Asistente de Marketing,[email protected],,,, 44,123,456,AR,name,SOLDADOR,[email protected],,,, 217,123,456,AR,name,Se requiere vendedores,, Loja , Quevedo, Guayas),[email protected] 218,123,456,AR,name,Ing. Civil recién graduado, Yaruquí,[email protected],,, 219,123,456,AR,name,ayudantes enfermeria,[email protected],,,, 220,123,456,AR,name,Trip Leader for International Youth Exchange,[email protected],,,, 221,123,456,AR,name,COUNTRY MANAGER / DIRECTOR COMERCIAL,[email protected],,,, 250,123,456,AR,name,Ayudante de Pasteleria,[email protected], Asesor,[email protected],[email protected], 251,123,456,AR,name,Ejecutiva de Ventas,[email protected],,,,
"bla,bla,bla"