Pandas 修改index
import pandas as pd
df = pd.DataFrame({‘a’: [1, 2 ,3], ‘b’: [4, 5, 6]})
方法1:
df.index = [11, 22, 33 ]
方法2
df.reset_index(drop=True, inplace=True) # drop=True表示原index不会以列的形式保存在df中
方法3
df.set_index(keys=[‘a’], inplace=True) # 将‘a’列作为index