法一:
pd.DataFrame( [ (第一行),(第二行),(第三行)] )df = pd.DataFrame([('bird', 389.0),
('bird', 24.0),
('mammal', 80.5),
('mammal', np.nan)],
index=['falcon', 'parrot', 'lion', 'monkey'],
columns=('class', 'max_speed'))
法二:
pd.DataFrame( {"字段1" : [],
"字段2" : [],
"字段3" : []} )
df = pd.DataFrame({
'store_id': [117002, 117002, 117002],
'sku_id': [773, 773,773],
'date': ["2022-01-01", "2022-01-02", "2022-01-03"],
'sales': [5, 7, 3],
'stock': [8, 10, 6]
})
法三:
pd.DataFrame( {"字段1" : pd.Series ( [], dtype='datetime64[ns]'),
"字段2" : pd.Series ( [], dtype='datetime64[ns]'),
"字段3" : pd.Series ( [], dtype='datetime64[ns]') } )
df = pd.DataFrame({'trans_time': pd.Series([], dtype='datetime64[ns]'),
'id': pd.Series([], dtype='int'),
'zone_id': pd.Series([], dtype='str')})
标签:df,dtype,DataFrame,生成,字段,pd,Series,几种
From: https://www.cnblogs.com/tian1022/p/17092352.html