import numpy as np import pandas as pd #创建方法一:多个series组成字典创建dataframe pp = {'bj':3000,'gz':2800,'sh':3200} area={'bj':290,'gz':310,'sh':150} pp_series = pd.Series(pp) area_series = pd.Series(area) citys = pd.DataFrame({'area':area_series,'population':pp_series}) print(citys) print('-'*50) #创建方法二:多个列表组成字典创建dataframe data1 = {'a':[1,2,3], 'b':[3,4,5], 'c':[5,6,7]} data=pd.DataFrame(data1) print(data) print('-'*50) #创建方法三:多个series组成列表 指定index citys = pd.DataFrame([area_series, pp_series],index=['population','area']) print(citys) print('-'*50) #一个Series指定columns data = pd.DataFrame(pp_series, columns=['population']) print(data) print('-'*50) #创建方式四:用二维数组,指定index和column a = np.arange(12).reshape(3,4) data = pd.DataFrame(a, index = list('abc'), columns=list('ABCD')) print(data)