Answers for "apply condition on all columns of data frame"

2

create the dataframe column based on condition

df.loc[df['column name'] condition, 'new column name'] = 'value if condition is met'
Posted by: Guest on May-10-2020
0

Pandas conditional collumn

import pandas as pd
import numpy as np

df = pd.DataFrame({'Type':list('ABBC'), 'Set':list('ZZXY')})
df['color'] = np.where(df['Set']=='Z', 'green', 'red')
print(df)
Posted by: Guest on October-23-2021

Code answers related to "apply condition on all columns of data frame"

Python Answers by Framework

Browse Popular Code Answers by Language