1)仅换掉index名称 df.index = list 2)调整index时,后面的项目也要跟着调整: df.reindex(list) 注意如果list中出现了df中没有的index,后面的项目会变成nan 举例: df=pd.DataFrame({'a':[1,2,3],'b':[4,5,6],'c':[7,8,9]},columns=['a','b','c'],index=['11','22','33']) print(df): a b c 11 1 4 7 22 2 5
import numpy as np import pandas as pd Pandas will be a major tool of interest throughout(贯穿) much of the rest of the book. It contains data structures and manipulation tools designed to make data cleaning(数据清洗) and analysis fast and easy in Python.
实例: import pymysql import pandas as pd import numpy as np from sqlalchemy import create_engine df = pd.DataFrame([[1,"Bob",0], [2,"Kim",1]],columns=["id","name","sex"]) df id name sex 0 1 Bob 0 1 2 Kim 1 f