Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.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 Pandas将数据帧索引为csv:写入x列但得到y别名_Python_Pandas - Fatal编程技术网

Python Pandas将数据帧索引为csv:写入x列但得到y别名

Python Pandas将数据帧索引为csv:写入x列但得到y别名,python,pandas,Python,Pandas,我使用的是Python 3.6.9和Pandas 0.24.2 我正在使用以下代码将数据帧保存到CSV: df.to_csv(price_filename, header=['Date', 'Open', 'High', 'Low', 'Close', 'Adjusted_close', 'Volume'], index=True) 我得到以下错误: 写了6个col,但得到了7个别名 这就是我的数据帧的外观: Open High Low Close

我使用的是Python 3.6.9和Pandas 0.24.2

我正在使用以下代码将数据帧保存到CSV:

df.to_csv(price_filename, header=['Date', 'Open', 'High', 'Low', 'Close', 'Adjusted_close', 'Volume'], index=True)
我得到以下错误:

写了6个col,但得到了7个别名

这就是我的数据帧的外观:

              Open    High     Low   Close  Adjusted_close  Volume                                                                            
Date
2020-10-16  618.50  630.75  615.50  625.25          625.25       0
2020-10-15  596.75  619.50  596.50  618.25          618.25   90299
2020-10-14  594.75  600.25  587.25  596.75          596.75   58370
2020-10-13  596.25  604.25  590.75  594.00          594.00   56418
2020-10-12  592.50  599.00  587.00  594.25          594.25   63837
我知道df中的列数与传递到
变量中的列表不匹配。但是,我将索引标志设置为True,但出现了错误。同样,删除索引标志也不能解决问题


如何使用列表中指定的列将文件保存到CSV?

使用
索引标签

df.to_csv(price_filename, header=['Open', 'High', 'Low', 'Close', 'Adjusted_close', 'Volume'], index_label="Date")

我们可以先使用


使用索引标签

df.to_csv(price_filename, header=['Open', 'High', 'Low', 'Close', 'Adjusted_close', 'Volume'], index_label="Date")

我们可以先使用


您需要将index=False添加到
to_csv()
函数中,然后才能将其保存到所需的format@HomunculusReticulli更好的是,我刚刚在
to_csv
中找到了
索引\u标签
段落。您需要在
to_csv()中添加一个index=False
功能,然后保存到所需的format@HomunculusReticulli更好的是,我刚刚在
to_csv
中找到了
索引\u标签
段落。。