1、reset_index()使用场景
继上文,将数据用sort_values进行排序后会发现索引被打乱,故此时需要重置索引
2、reset_values用法
df.reset_index(level=None, drop=False, inplace=False,col_level=0,col_fill='')
#df1重置索引前,索引是乱序的:
company data_month
0 公司A 2020-12
2 公司A 2021-3
1 公司B 2020-9
3 公司C 2020-10
#重置索引后:
df1.reset_index(drop=True,inplace=True)
print(df1)
company data_month
0 公司A 2020-12
1 公司A 2021-3
2 公司B 2020-9
3 公司C 2020-10
3、各参数及其含义(drop和inplace比较常用)
参数 | 含义</ |