创建列的Int64Index

2024-06-28 19:09:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚刚开始学习Python代码,我正在尝试在数据帧中创建一个列的Int64Index并打印该索引。我正在尝试以下代码,但它们都不起作用:

第一:

age = index(data = df.columns(age)).astype(Int64, copy=True)

备选方案:

age = df.Int64Index(name = age)

为了便于参考,请看图片,我举了另一个例子,其中我使用了Groupby()year并计算了平均值,得到了结果数据框。我想将Int64Index添加到结果数据帧中

This image shows the resulted dataframe created from groupby()


Tags: columns数据代码nametruedfagedata