import pandas as pd import numpy as np if __name__ == '__main__': t1=pd.DataFrame(np.arange(12).reshape(3,4)) print(t1)
替换索引名称:
t2=pd.DataFrame(np.arange(12).reshape(3,4),index=list('abc'),columns=list('abcd')) print(t2)
通过字典创建:
''' 通过字典创建 ''' p1={"name":['zhangsan','xiaoming'],"age":[19,21],"tel":[10086,10010]} print(pd.DataFrame(p1))
通过列表创建:
''' 通过列表创建 ''' p2=[{'name':'zhangsan','age':19,'tel':10086},{'name':'xioaming','age':21,'tel':10010}] print(pd.DataFrame(p2))