问题
when I save my dataframe to csv file, It is combined in one column, I want each column of data frame to appear in separated column in CSV file, this is the code
df.to_csv(r'myData.csv',sep=',',encoding="utf-8",columns=['id','created_at','text'])
but it is saved in one column of CSV file, in A column separated by comma
0,2019-09-28 08:58:13,"The TRUTH about Carbon Dioxide"
and I want each value in separated column A,B,C
Is there any way to do that? what I got is
what I want is:
thank you
回答1:
In a csv file, each row is a separate line, and in this row, the different columns are separated by comma.
So
`0,2019-09-28 08:58:13,"The TRUTH about Carbon Dioxide"`
is a row of the data frame, not a column. The columns are still separated by comma in the csv file.
回答2:
OK
the answer is simply changing sep=',' to sep=';'
来源:https://stackoverflow.com/questions/58146464/how-i-can-save-each-column-of-dataframe-to-separated-column-in-csv-file