Pandas的数据类型:1. Series, 2. DataFrame
1. Series
series与列表和numpy数据的区别是 series带索引。
(Series与DataFrame区别是,Series是1维,DataFrame是2维。)
l=[1,3,6]
sr = pd.Series(l) #通过列表生成Series。
2.DataFrame
构造DataFrame:
sr = np.arange(20).reshape(4,5) #用numpy arange()方法和reshape方法生成4x5 numpy矩阵
df = pd.DataFrame(sr) #用numpy矩阵生成DataFrame。未指定行列索引。
col_index = ["colA","colB","colC","colD","colE"]
row_index = ['row1","row2","row3","row4"]
df = pd.DataFrame(sr, columns=col_index, index=row_index) #指定行列索引
#用Series拼接DataFrame:
r1 = pd.Series['C','D','E']
r2 = pd.Deries['001','002,'005']
df = pd.DataFrame([r1,r2])