【发布时间】:2020-03-08 05:09:29
【问题描述】:
我使用 pandas 读取了一个包含 python 数据框的 excel 文件。最初使用 ExcelWriter 将数据框转换为 excel 文件。数据框在 excel 中如下所示:
df:
Index Variables
0 Index(['Growth', 'Pure growth', 'Value'], dtype='object')
1 Index(['Growth', 'Pure growth', 'Quality'], dtype='object')
.
.
.
但是,在读取文件后,python 无法识别索引中的变量列而不是字符串。
type(df['Variables'][0])
>>str
如何将列转回索引格式?
感谢您的帮助
【问题讨论】:
-
你能展示一下你目前正在使用的代码吗?
-
您能发布包含一些示例数据的代码吗?这将有助于重现问题,这是目前无法做到的
标签: python pandas list dataframe