Search
 
SCRIPT & CODE EXAMPLE
 

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()
Comment

PREVIOUS NEXT
Code Example
Python :: bulk upload with dictionary or list in django moels 
Python :: Insert Multiple Images to Excel with Python 
Python :: python integrated with activeX 
Python :: How to count a consecutive series of positive or negative values in a column in python 
Python :: multivariate classification python 
Python :: f2 polar or nonpolar 
Python :: python dataset createdimension unlimited 
Python :: python - concatenate if null 
Python :: mean first passage time markov chain python 
Python :: ler arquivo xls no pandas 
Python :: combine all lines with same value of a column unix 
Python :: como fazer print no python 
Python :: make image to string to use in tkinter 
Python :: python difference between multiprocessing pool and threadpool 
Python :: python if dataframe has at least one row 
Python :: equivalent of case_when in r in pandas 
Python :: fibonacci sequence python 2.7 
Python :: multiprocessing module in python 
Python :: Horizontal bar graph OO interface 
Python :: problems on loops and if else statements 
Python :: pandas normalize rows to max value 
Python :: how to subset a dataframe in python based on multiple categorical values 
Python :: mechanize python LE #3 
Python :: how to visualize pytorch model filters 
Python :: HOW TO REPLACE NUMBERS WITH ASTERISK IN PYTHON 
Python :: pandas within group pairwise distances 
Python :: pandas from multiindex to single index 
Python :: python deconstruct tuple 
Python :: python string formatting - string truncating with format() 
Python :: Validation using voluptuous python library 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =