我在熊猫的dataframe (df)中有一篇专栏文章叫做"9-7“。当我使用df.to_csv('df.csv')
保存数据时,列的标题将更改为7-9月。意思是九月七日的日期。然而,我需要标题"9-7“。
发布于 2018-04-04 08:13:20
这与excel对数据的解释有关。csv文件只不过是一个字符串格式的表。
如果要继续使用excel,可以使用to.excel()
函数:
import pandas as pd
pd.DataFrame({'9-7':[1]}).to_csv('test.csv',index=False) # This will not work
pd.DataFrame({'9-7':[1]}).to_excel('test.xlsx',index=False) # This will
https://stackoverflow.com/questions/49645667
复制相似问题