📜  如何获取两列值匹配的位置? - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:33.475000             🧑  作者: Mango

代码示例1
import pandas as pd 
import numpy as np 

#1
df.index[df['BoolCol'] == True].tolist()

#2
df.index[df['BoolCol']].tolist()

#ex : 
df = pd.DataFrame({'fruit1': np.random.choice(['apple', 'orange', 'banana'], 10),
                    'fruit2': np.random.choice(['apple', 'orange', 'banana'], 10)})

out = df.index[df.fruit1 == df.fruit2].tolist()