[英]How to slice if the header and index both are int in pandas?
索引和标头都是int。 如何通过索引名称和标头名称切片df?
2001 2002 2003
50425 139 140 136
50434 122 121 131
50514 128 125 177
50527 127 129 154
50603 128 120 169
50618 124 126 123
In [174]: df.loc[50434:50600, 2002:2003]
Out[174]:
2002 2003
50434 121 131
50514 125 177
50527 129 154
如果您使用字符串作为列名:
In [177]: df.columns
Out[177]: Index(['2001', '2002', '2003'], dtype='object')
# ^ ^ ^ ^ ^ ^
In [178]: df.loc[50434:50600, '2002':'2003']
Out[178]:
2002 2003
50434 121 131
50514 125 177
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.