在包含字符串作为值的数据框中找到行的索引?

时间:2019-11-25 10:51:25

标签: python python-3.x pandas numpy indexing

我有2个数据帧df和df1,可以从中比较这些值。该代码的确切期望是:

1)遍历数据帧df并在满足特定条件时进行迭代     条件下,它将值保存在变量“值”的第10列中。    2)它调用函数GDN_func,然后在该数据帧df1中,     它遍历列'B',即第二列并比较其     'items'值,如果匹配则返回row_index

我已经将两个Excel工作表都转换为数据帧。 row_index=df.index.get_loc(item)将不会给出结果,因为该变量存储为字符串。

这里的代码只是一部分。

我附上了我的两个数据框和代码片段。

def GDN_func():
#defining GDN_func
    for item in (df1.iloc[:, 1]):
        if(item==value):
            p=df1[1].values.tolist().index(item)
            print(p) # This is not working

for row in range(0, mr-1):
    if((df.loc[row]['ATC']=='All') &
       (df.loc[row]['Data_Grain']=='Leadership Capability')):
        value=df.loc[row][10]
        GDN_func()
    else:
        print("These are different rows")

0 个答案:

没有答案