为什么我们需要在python中重置数据帧列中的索引?

2024-05-19 12:51:25 发布

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

df_countries = df_can.loc[['Denmark', 'Norway', 'Sweden'], years].transpose()

df_total = pd.DataFrame(df_countries.sum(axis=1))

df_total.reset_index(inplace=True)

df_total.columns = ['year', 'total']

df_total['year'] = df_total['year'].astype(int)

df_total.head()

根据注释,重置索引以将其作为df_tot数据帧中的一列放回。有人能解释一下为什么我们需要重置吗


Tags: dataframedfyearcountriescanloc重置total