python - 获取类型错误 : 'list' object is not callable when setting index in Pandas Dataframe

标签 python pandas indexing set

我有简单的 Pandas Dataframe:

data.head(5)


> Date  Time    Open    High    Low Close   Vol OI
> 0 02/02/1993  16:00   44.23   44.38   44.13   44.34   201300  0
> 1 02/03/1993  16:00   44.41   44.84   44.38   44.82   529400  0
> 2 02/04/1993  16:00   44.97   45.10   44.88   45.00   531500  0
> 3 02/05/1993  16:00   44.97   45.06   44.73   44.97   492100  0
> 4 02/08/1993  16:00   44.97   45.13   44.92   44.98   596100  0

我想将“日期”列设置为索引:

data.set_index('Date')

但出现错误“TypeError: 'list' object is not callable”

TypeError                                 Traceback (most recent call last)
<ipython-input-59-a610da45b82c> in <module>()
----> 1 data.set_index('Date')

TypeError: 'list' object is not callable

当前数据中的索引为RangeIndex:

data.index
RangeIndex(start=0, stop=5873, step=1)

有什么提示为什么我无法使用日期列设置索引吗?

谢谢。

最佳答案

使用 set_index 命令时,我遇到了同样的问题“TypeError: 'list' object is not callable”。我通过首先调用“reindex()”方法然后使用 set_index 得到了解决方案。希望对你有帮助。 阿米尔

关于python - 获取类型错误 : 'list' object is not callable when setting index in Pandas Dataframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37481563/

相关文章:

python - 我需要导入什么才能访问我的模型?

python - 在 ", "上连接 3D pandas 数组中的值,使其成为 2D 数组

python - 创建可变数量的类实例

python - 如何在不创建实例的情况下选择性地访问类方法

python - Pandas DataFrame 中匹配行的索引 [Python]

python - 将列添加到现有数据框中,但将所有数字输入为 NaN

mysql - 如何在仍然利用索引的同时在两列之间进行查询?

sql - 优化以通配符开头的 LIKE 表达式

numpy - 遍历多维 Numpy 数组

python - 我该如何解决 - TypeError : cannot safely cast non-equivalent float64 to int64?