df1[列索引].dtype: 查看指定列的数据类型
import pandas as pd
df1=pd.read_excel('.\Print pack disconnection record.xlsx',usecols=[0,1,3,4])
print(df1["Date"].dtype) #datetime64[ns]
print(df1["Pack"].dtype) #object
astype("float64"): 转换一列的数据类型 ( float64...int64)
索引:
行索引:index……列索引:columns
df1.index=[ list] :将列表设定为新的行索引
df1.set_index(列名称):将指定列设定为行索引.
df1.rename(colums={列名:新列名}) : 重命名索引 (同样需要重新赋值)
需要特别注意的是,set_index指令相当于赋值一个新列表,把新列表里的指定列设定为行索引,如果不对数据表重新赋值,不会改变原数据表的结果。
import pandas as pd
df1=pd.read_excel('.\Print pack disconnection record.xlsx',usecols=[0,1,3,4])
print(df1)
df1=df1.set_index("Date") #此处需要重新赋值
df1=df1.rename(columns={"Pack":"Pack_name"})
df1=df1.rename(index={1:"一",2:"二"})
print(df1)