Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to get the positions where values of two columns match?

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()
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #How #positions #values #columns
ADD COMMENT
Topic
Name
8+4 =