【发布时间】:2017-10-12 08:35:00
【问题描述】:
我想问你,如何在 DataFrame 中选择具有相同索引号的行。示例:
df=
A, B, C,
0 1. 2. 1.
1 2. 2. 2.
2 2. 2. 2.
3 3. 3. 4.
A, B, C,
0 1. 2. 1.
1 2. 2. 2.
2 2. 2. 0.
3 3. 3. 4.
A, B, C,
0 1. 2. 1.
1 2. 2. 2.
2 0. 2. 2.
3 3. 3. 4.
我希望:
df1=
A, B, C,
2 2. 2. 2.
2 2. 2. 0.
2 0. 2. 2.
我正在使用df.loc[2],但只显示第一组数据。也使用了df1=df.set_index(['2']),也不起作用。提前致谢!
【问题讨论】:
-
索引中不能有重复项。
-
你能粘贴 df.index 和 df.columns 的输出吗
-
磨损了,我的
df.index= Out[101]: RangeIndex(start=0, stop=874, step=1)但我可以看到可变长度的索引 [1,2,3,4,5,,1,2,3,,1,2,3... ] 我的专栏的输出是:Index(['Unnamed: 0', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34' -
您能粘贴示例输入和示例输出以及代码吗?到目前为止,您在解决问题方面做了哪些尝试?
标签: python pandas sorting indexing pandas-loc