这是我的熊猫资料
In [7]:
dframe = pd.DataFrame({"A":list("abcde"), "B":list("fghij")}, index=[10,11,12,13,14])
dframe
Out[7]:
A B
10 a f
11 b g
12 c h
13 d i
14 e j问题1:如何获得第三行的索引?答案是12
问题2:如何删除第三行?
发布于 2016-04-26 23:02:10
您可以直接下标到df的index属性,并将其传递给drop以删除该特定行:
In [98]:
dframe.index[2]
Out[98]:
12以上所示的index对象类似于数组,它支持直接使用基于整数的定位来订阅。
In [99]:
dframe.drop(dframe.index[2])
Out[99]:
A B
10 a f
11 b g
13 d i
14 e j发布于 2016-04-26 22:58:48
索引:
In [158]: dframe.iloc[2]
Out[158]:
A c
B h
Name: 12, dtype: object或
In [159]: dframe.iloc[[2]]
Out[159]:
A B
12 c hhttps://stackoverflow.com/questions/36877259
复制相似问题