类型错误:“_AtIndexer”对象在 pandas 中不可调用

Cre*_*sht 5 python dataframe python-3.x pandas

我有一个DataFrame名为 的对象df,我想生成一个格式正确的日期列表。(datetime模块已正确导入)

我写:

dates = [datetime.date(df.at(index, "year"), df.at(index, "month"), df.at(index, "day")) for index in df.index]
Run Code Online (Sandbox Code Playgroud)

这给出了标题中的错误。

如果有帮助,这就是以下的价值df.head()

   year  month  day  smoothed   trend
0  2011      1    1    391.26  389.76
1  2011      1    2    391.29  389.77
2  2011      1    3    391.33  389.78
3  2011      1    4    391.36  389.78
4  2011      1    5    391.39  389.79
Run Code Online (Sandbox Code Playgroud)

(这对我来说是新的,所以我可能误解了文档)

Mus*_*dın 10

df.at不是可调用的,而是支持索引的属性。因此,将括号更改为方括号:

df.at[index, "year"]
Run Code Online (Sandbox Code Playgroud)

即,(to[和类似的关闭。