numpy 如何隐藏Pandas Dataframe 的索引列?

anauzrmj  于 2022-12-26  发布在  其他
关注(0)|答案(1)|浏览(340)

请帮助,我需要删除“日期”索引列,否则“日期”将出现在第一列的操作

heat_ds = pd.DataFrame(columns=['PFE','GS','BA','NKE','V','AAPL','TSLA','NVDA','MRK','CVX','UNH'])

heat_ds['PFE'] = pfizer['Close']

heat_ds['GS'] = goldmans['Close']

heat_ds['BA'] = boeingc['Close']

heat_ds['NKE'] = nike['Close']

heat_ds['V'] = visa['Close']

heat_ds['AAPL'] = aaple['Close']

heat_ds['TSLA'] = tesla['Close']

heat_ds['NVDA'] = tesla['Close']

heat_ds['MRK'] = tesla['Close']

heat_ds['CVX'] = chevronc['Close']

heat_ds['UNH'] = unitedh['Close']
gfttwv5a

gfttwv5a1#

首先,date代表索引。要删除它,首先重置索引,从 Dataframe 的索引中删除date,使其成为普通列,然后删除该列。

heat_ds = heat_ds.reset_index()
heat_ds = heat_ds.drop('index', axis=1)

或在一行中

heat_ds = heat_ds.reset_index(drop=True)

相关问题