Logical or operation of column in pandas python

Logical or operation of two columns in pandas python can be done using logical_or function. Let’s see how to get

  • Logical or operation 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,41],
   'Score2':[5,67,54,56,12]}

df1 = pd.DataFrame(df1,columns=['State','Score1','Score2'])
print(df1)

df1 will be

Logical or operator in pandas 1

 

Logical or operation of two columns in pandas python:

Logical or of two columns in pandas python is shown below . It results in true when at least one score is greater than 40


df1['Pass_Status_atleast_one'] = np.logical_or(df1['Score1'] > 40, df1['Score2'] > 40)
print(df1)

So the resultant dataframe will be

Logical or operator in pandas 2

 

p Logical or operation of column in pandas python                                                                                                           n Logical or operation of column in pandas python

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.

    View all posts