如何在DataFrame索引某一行

来源:互联网 发布:淘宝美颜切图怎么使用 编辑:程序博客网 时间:2024/06/06 06:45

有行索引和列索引

df=DataFrame(np.arange(16).reshape((4,4)),index=['a','b','c','d'],columns=['one','two','three','four'])
dfOut[14]:    one  two  three  foura    0    1      2     3b    4    5      6     7c    8    9     10    11d   12   13     14    15
po=df.loc[['a','b'],:] 
poOut[16]:    one  two  three  foura    0    1      2     3b    4    5      6     7

默认的索引

dd=DataFrame(np.arange(81).reshape((9,9)))ddOut[20]:     0   1   2   3   4   5   6   7   80   0   1   2   3   4   5   6   7   81   9  10  11  12  13  14  15  16  172  18  19  20  21  22  23  24  25  263  27  28  29  30  31  32  33  34  354  36  37  38  39  40  41  42  43  445  45  46  47  48  49  50  51  52  536  54  55  56  57  58  59  60  61  627  63  64  65  66  67  68  69  70  718  72  73  74  75  76  77  78  79  80
pp=dd.loc[[1,5,7],:]ppOut[25]:     0   1   2   3   4   5   6   7   81   9  10  11  12  13  14  15  16  175  45  46  47  48  49  50  51  52  537  63  64  65  66  67  68  69  70  71
原创粉丝点击