Python 查找特定行中的值以特定字符串开头的索引-AttributeError:';数据帧';对象没有属性';ix和x27;
我有这样一个数据框架:Python 查找特定行中的值以特定字符串开头的索引-AttributeError:';数据帧';对象没有属性';ix和x27;,python,pandas,error-handling,attributeerror,Python,Pandas,Error Handling,Attributeerror,我有这样一个数据框架: A B C 1 2 3 4 5 6 nullnull 0 1 7 8 9 现在我想找出nullnull所在行的索引。使用此索引进行切片,以便仅获取此索引之前的行 我试过这样的方法: row = df.ix[df['A'].startswith("nullnull")].index.tolist() 得到了这个错误: AttributeError: 'DataFrame' object has no attribute 'ix' 我如何使用star
A B C
1 2 3
4 5 6
nullnull 0 1
7 8 9
现在我想找出nullnull
所在行的索引。使用此索引进行切片,以便仅获取此索引之前的行
我试过这样的方法:
row = df.ix[df['A'].startswith("nullnull")].index.tolist()
得到了这个错误:
AttributeError: 'DataFrame' object has no attribute 'ix'
我如何使用
startswith
或使用其他方法来实现这一点?更改为loc
或.iloc
row = df.loc[df['A'].str.startswith("nullnull")].index.tolist()
row
Out[549]: [2]