问题
I need to generate a csv using pandas to_csv function. I tried quote=csv.QUOTE_NONNUMERIC. But for one of the date time column I dont need double quotes.
Is there a way to select the columns for which we want double quotes?
回答1:
Thanks people. I got the answer so just thought to share.
First I got the list of headers to be quoted and looped them something like below:
for col in quoteColumnsList:
df[col] = '"' + df[col] + '"'
Here my quotechar is '"'. Now I used to_csv with quote parameter as csv.QUOTE_NONE. This way we get the double quotes only to the required columns.
来源:https://stackoverflow.com/questions/47647319/quote-only-the-required-columns-using-pandas-to-csv