Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将索引保存到excel_Python_Pandas_Dataframe - Fatal编程技术网

Python 如何将索引保存到excel

Python 如何将索引保存到excel,python,pandas,dataframe,Python,Pandas,Dataframe,我想将此格式保存在excel文件中 我使用以下代码来保存 df.index = Q_df.index.to_period("Q") df.to_excel(path, sheet_name = 'Data') writer.save() 一旦保存,但我有这个格式 请帮我找到一个解决方案。trydf.index=Q\u df.index.to\u period(“Q”).astype(str)trydf.index=Q\u df.index.to\u period(“Q”

我想将此格式保存在excel文件中

我使用以下代码来保存

df.index = Q_df.index.to_period("Q")
df.to_excel(path, sheet_name = 'Data')
writer.save()
一旦保存,但我有这个格式


请帮我找到一个解决方案。

try
df.index=Q\u df.index.to\u period(“Q”).astype(str)
try
df.index=Q\u df.index.to\u period(“Q”).astype(str)