正在做
# extract data
df = pd.read_csv('https://covid.ourworldindata.org/data/ecdc/total_cases.csv')
df.set_index('date', inplace=True)
#transpose columns to rows
df = df.T
# swap all NAN with 0.0
df = df.fillna(0.0)
我有:
date 2020-04-20 2020-04-21
World 2355853.0 2431890.0
Afghanistan 996.0 1031.0
Albania 562.0 584.0
Algeria 2629.0 2718.0
现在,我希望删除第一列以创建索引,最后以:
2020-04-20 2020-04-21
0 2355853.0 2431890.0
1 996.0 1031.0
2 562.0 584.0
3 2629.0 2718.0
如何?
编辑:
date 2019-12-31 2020-01-01 2020-01-02 2020-01-03 2020-01-04 2020-01-05 \
0 27.0 27.0 27.0 44.0 44.0 59.0
1 0.0 0.0 0.0 0.0 0.0 0.0
2 0.0 0.0 0.0 0.0 0.0 0.0
答案 0 :(得分:1)
尝试一下:
df = df.reset_index().drop('date', axis=1)
OR
df = df.reset_index(drop=True)