Closed
Description
Hi,
My data frame contains unicode strings. Now when I use 'to_csv' without any quoting parameter, I get a csv file where certain fields (2 out of 11 to be exact) are in double quotes. For example:
28,"May 8, 2013 10:22 AM","76th St, Yates Blvd",41.75717,-87.56633,3,-,1,4,-
Now when I use csv.QUOTE_NONE i get the following error:
Error: need to escape, but no escapechar set
So i do the following (quoting=csv.QUOTE_NONE, escapechar='"'), and I get this:
28,May 8", 2013 10:22 AM,76th St", Yates Blvd,41.75717,-87.56633,3,-,1,4,-
So I get a new quote (") in those 2 fields. How to get around this problem? Thanks.
Sample code is below:
id = [u'1']
date = [u'Jan 12, 2013 08:30 AM']
location = [u'Ashland Avenue, Polk Street']
vehicles = [u'4']
drunken_persons = [u'-']
fatalities = [u'3']
persons = [u'4']
pedestrians = [u'-']
data = pd.DataFrame({'#':id, 'Date':date, 'Vehicles':vehicles, 'Drunken Persons':drunken_persons, 'Fatalities':fatalities, 'Persons':persons, 'Pedestrians':pedestrians, 'Location':location})
data[['#','Date','Location','Vehicles','Drunken Persons','Fatalities','Persons', 'Pedestrians']].astype(str).to_csv('Test.csv', sep=',', index = False, quoting=csv.QUOTE_NONE, escapechar='"')