如何在DataFrame索引某一行
有行索引和列索引
df=DataFrame(np.arange(16).reshape((4,4)),index=['a','b','c','d'],columns=['one','two','three','four'])
df
Out[14]:
one two three four
a 0 1 2 3
b 4 5 6 7
c 8 9 10 11
d 12 13 14 15
po=df.loc[['a','b'],:]
po
Out[16]:
one two three four
a 0 1 2 3
b 4 5 6 7
默认的索引
dd=DataFrame(np.arange(81).reshape((9,9)))
dd
Out[20]:
0 1 2 3 4 5 6 7 8
0 0 1 2 3 4 5 6 7 8
1 9 10 11 12 13 14 15 16 17
2 18 19 20 21 22 23 24 25 26
3 27 28 29 30 31 32 33 34 35
4 36 37 38 39 40 41 42 43 44
5 45 46 47 48 49 50 51 52 53
6 54 55 56 57 58 59 60 61 62
7 63 64 65 66 67 68 69 70 71
8 72 73 74 75 76 77 78 79 80
pp=dd.loc[[1,5,7],:]
pp
Out[25]:
0 1 2 3 4 5 6 7 8
1 9 10 11 12 13 14 15 16 17
5 45 46 47 48 49 50 51 52 53
7 63 64 65 66 67 68 69 70 71