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

0

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()
Posted by: Guest on June-04-2020
0

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()
Posted by: Guest on June-04-2020

Code answers related to "How to get the positions where values of two columns match?"

Python Answers by Framework

Browse Popular Code Answers by Language