首页 > 解决方案 > 列在 DataFrame.info() 中不可见

问题描述

我有以下称为 large5 的 DataFrame:

country     United Arab Emirates    Djibouti    Andorra     Saudi Arabia    Marshall Islands
1971-1980   NaN                     NaN         NaN         NaN             NaN
1981-1990   1.082990                0.686978    0.370541    0.603019        0.410776
1991-2000   0.738127                0.366770    0.335852    0.370899        0.225249
2001-2010   1.270588                0.208094    0.255028    0.296046        0.097677
2011-2020   0.254555                -0.078750   -0.212721   0.025291        -0.165853
diff        0.828435                0.765728    0.583262    0.577727        0.576628

在运行large5.info() 时,我无法查看“国家”列,因此无法重命名或在我的可视化中使用它

<class 'pandas.core.frame.DataFrame'>
Index: 6 entries, 1971-1980 to diff
Data columns (total 5 columns):
United Arab Emirates    5 non-null float64
Djibouti                5 non-null float64
Andorra                 5 non-null float64
Saudi Arabia            5 non-null float64
Marshall Islands        5 non-null float64
dtypes: float64(5)
memory usage: 288.0+ bytes

运行large5.reset_index(inplace=True)也不起作用,因为列名更改为“索引”,我无法重命名它或在我的可视化中正确使用它。任何建议,将不胜感激。

标签: pythonpandasdataframe

解决方案


首先使用DataFrame.rename_axis

largenew = large5.rename_axis('Date').reset_index()

推荐阅读