Logical and operation of two columns in pandas python can be done using logical_and function. Let’s see how to get
- Logical and operator of column in pandas python
With examples
First let’s create a dataframe
import pandas as pd import numpy as np df1 = { 'State':['Arizona AZ','Georgia GG','Newyork NY','Indiana IN','Florida FL'], 'Score1':[4,47,55,74,31], 'Score2':[5,67,54,56,12]} df1 = pd.DataFrame(df1,columns=['State','Score1','Score2']) print(df1)
df1 will be
Logical and operation of two columns in pandas python:
Logical and of two columns in pandas python is shown below. It will result in True when both the scores are greater than 40.
df1['Pass_Status'] = np.logical_and(df1['Score1'] > 40,df1['Score2'] > 40) print(df1)
So the resultant dataframe will be