- 行标签——index
- 列——columns
- 建立dataframe
import pandas as pd
data=[['mark',55,'Italy',4.5,'Europe'],
['John',33,'China',3.8,'Asian']]
df=pd.DataFrame(data=data,columns=['age','name','country','score','continent'],
index=[1001,1002])
4. 给索引取名
df.index.name='user'
5. 还原成普通的列
print(df.reset_index())
6. 设置新的索引
print(df.reset_index().set_index('country'))