I have several csv files in which each of them has different formats. Here an sample of two different csv files. Please look at the format not values.
csv_2 "xxxx-0147-xxxx-194443,""Jan 1, 2017"",7:43:43 AM PST,,Google fee,,Smart Plan (Calling & Texting),com.yuilop,1,unlimited_usca_tariff_and,mimir,US,TX,76501,USD,-3.00,0.950210,EUR,-2.85"
csv_2 "1305-xxxx-0118-54476..1,""Jan 1, 2017"",7:17:31 AM PST,,Google fee,,Smart Plan (Calling & Texting),com.yuilop,1,unlimited_usca_tariff_and,htc_a13wlpp,US,TX,79079,USD,-3.00,0.950210,EUR,-2.85"
csv_1 GPA.xxxx-2612-xxxx-44448..0,2017-02-01,1485950845,Charged,m1,Freedom Plan (alling & Texting),com.yuilop,subscription,basic_usca_tariff_and,USD,2.99,0.00,2.99,,,07605,US
csv:1 GPA.xxxx-6099-9725-56125,2017-02-01,1485952917,Charged,athene_f,Buy 100 credits (Calling & Texting),com.yuilop,inapp,100_credits,INR,138.41,0.00,138.41,Kolkata,West Bengal,700007,IN
As u see csv_2 is included " and sometimes "", however csv_1 is a simple format. I get all csvs on the demand and they are a lot and huge. I tried to use sniffer in order to recognise dialect automatically. But this is not enough and I don't get the reasonable response for the one that has "" . Is there anybody who can guid me how to solve this problem?
Python code 2.7
With open(file, 'rU') as csvfile:
dialect = csv.Sniffer().sniff(csvfile.read(2024))
csvfile.seek(0)
reader = csv.reader(csvfile, dialect)
for line in reader:
print line
Parameter Values:
dialect.escapechar None
dialect.quotechar "
dialect.quoting 0
dialect.escapechar None
dialect.delimiter ,
dialect.doublequote False
result
csv_1 ['GPA.13xx-xxxx-9725-5xxx', '2017-02-01', '1485952917', 'Charged', 'athene_f', 'Buy 100 credits (Calling & Texting)', 'com.yuilop', 'inapp', '100_credits', 'INR', '138.41', '0.00', '138.41', 'Kolkata', 'West Bengal', '700007', 'IN']
csv_2 ['1330-xxxx-5560-xxxx,"Jan 1', ' 2017""', '12:35:13 AM PST', '', 'Google fee', '', 'Smart Plan (Calling & Texting)', 'com.yuilop', '1', 'unlimited_usca_tariff_and', 'astar-y3', 'US', 'NC', '27288', 'USD', '-3.00', '0.950210', 'EUR', '-2.85"']
In csv_2 , you see a mess . date is separated by comma specially date field and also all the row considered as a string. How can I change my code in order to have the same result as csv_1?