1. 介绍
DataFrame unifies two or more Series into a single data structure.Each Series then represents a named column of the DataFrame, and instead of each column having its own index, the DataFrame provides a single index and the data in all columns is aligned to the master index of the DataFrame.
这段话的意思是,DataFrame提供的是一个类似表的结构,由多个Series组成,而Series在DataFrame中叫columns(理解有错请指出,(逃~
2. 相关操作
a.create
pd.DataFrame()
参数:
1、二维array;
2、Series 列表;
3、value为Series的字典;
a.1、二维array
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
a.2、Series列表(效果与二维array相同)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
a.3、value为Series的字典结构;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
注:若创建使用的参数中,array、Series长度不一样时,对应index的value值若不存在则为NaN
b.属性
b.1 .columns :每个columns对应的keys
b.2 .shape:形状,(a,b),index长度为a,columns数为b
b.3 .index;.values:返回index列表;返回value二维array
b.4 .head();.tail();
c.if-then 操作
c.1使用.ix[]
- 1
- 2
- 3
- 1
- 2
- 3
df.ix[条件,then操作区域]
c.2使用numpy.where
- 1
- 2
- 3
- 1
- 2
- 3
np.where(条件,then,else)
d.根据条件选择取DataFrame
d.1 直接取值df.[]
- 1
- 2
- 3
- 1
- 2
- 3
d.2 使用.loc[]
- 1
- 2
- 3
- 1
- 2
- 3
(还有很多种方法就不一一列举了)
e.Grouping
e.1groupby 形成group
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
e.2 使用get_group 取出其中一分组
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8