Pandas 1.生成对象
import numpy as np
import pandas as pd
s = pd.Series([1,3,5,np.nan,6,7])
print(s)
#含日期时间索引与标签的 NumPy 数组生成
dates = pd.date_range('20200202',periods=6)
print(dates)
df = pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('DFGH'))
print(df)
#series字典对象生成DataFrame
df2 = pd.DataFrame({
'A':2,
'B':pd.Timestamp('20200202'),
'C':pd.Series(1,index=list(np.arange(4)),dtype='float32'),
'D':pd.Categorical(['test','train','test','train']),
'F':'orz'
}
)
print(df2)
运行结果:
![](https://img.haomeiwen.com/i11564851/5161c04c5209d807.png)
![](https://img.haomeiwen.com/i11564851/506984b82d0e12dc.png)
p
网友评论