Skip to content Skip to sidebar Skip to footer

Comparing Multiple Columns Using Python?

I am trying to compare multiple columns and assign the boolean value to a new column called New Column. Please find the sample data below. df = pd.DataFrame({ 'date1':['2000-03

Solution 1:

Use & for condition.

Example code is here.

df['New Column'] = '0'
df.loc[(df['date1'] <= df['date2']) & (df['date2'] <=  df['date3']), 'New Column'] = '1'

Post a Comment for "Comparing Multiple Columns Using Python?"