一.使用numpy创建
import pandas as pd
import numpy as np
df = pd.DataFrame(np.arange(16).reshape((4,4)),index=list('abcd'),columns=['one','two','three','four'])
df
二.由Series组成的字典
df3 = pd.DataFrame({'one':pd.Series([0,1,2,3]),'two':pd.Series([4,5,6,7]),'three':pd.Series([8,9,10,11]),'four':pd.Series([12,13,14,15])},columns=['one','two','three','four'])
df3
输出为:
自定义行索引;
df4 = pd.DataFrame({'one':pd.Series([0,1,2,3],index=list('abcd')),'two':pd.Series