我有数据框,其中行索引是日期。我想调用to_csv
我可以将行索引格式指定为%Y%m%d
,它似乎对我不起作用,因为行索引输出的格式为%Y-%m-%d
,无论如何强制此方法输出所需的行索引?
我可以迭代行输出作为我想要的格式,但对我来说太慢了。 这是我输入csv文件的代码。
df.to_csv(fn, na_rep='nan', header=False, index=True, date_format="%Y%m%d")
输出看起来像:
2000-01-05,0.0,0.0,0.0,0.0,0.0,25.5,25.4,25.4,25.36,0.0
我想看起来像:
20000105,0.0,0.0,0.0,0.0,0.0,25.5,25.4,25.4,25.36,0.0