pandas.DataFrame 操作 这篇文章说的很好。
总结:
DataFrame 有属性和索引的概念,属性即列,索引即行
DataFrame 取一列得到Series,取多列得到DataFrame
(Pdb) type(data['Test 1'])
84 Theta_min = result[0] <class 'pandas.core.series.Series'>
(Pdb) type(data[['Test 1', 'Test 2']])
88 print 'Debug' <class 'pandas.core.frame.DataFrame'>
取行,必须要用冒号:,否则会被当成取列而报错
(Pdb) data[:2]
Test 1 Test 2 Accepted Ones F10 F20 F21 F30 \
0 0.051267 0.69956 1 1 0.051267 0.002628 0.035864 0.000135
1 -0.092742 0.68494 1 1 -0.092742 0.008601 -0.063523 -0.000798
F31 F32 F40 F41 F42 F43
0 0.001839 0.025089 0.000007 0.000094 0.001286 0.017551
1 0.005891 -0.043509 0.000074 -0.000546 0.004035 -0.029801
(Pdb) data[2]
*** KeyError: 2
最简单的取任意行和任意列的方法是dara.iloc[], 而且这种方法是可以对原数据data修改的
(Pdb) data.iloc[3:7,1:4]
Test 2 Accepted Ones
3 0.502190 1 1
4 0.465640 1 1
5 0.209800 1 1
6 0.034357 1 1