Add a new column (conditional)



examples/pandas/temprature.csv
name,temp
Ella,36.6
Maor,40
Oren,38.2
Gal,37


examples/pandas/temprature.py
import sys
import pandas as pd

filename = 'temprature.csv'
df = pd.read_csv(filename)
print(df)
print()

def covid_instructions(row):
    return "stay home" if row['temp'] >= 38 else "go to work"

df['covid_instructions'] = df.apply(covid_instructions, axis=1)

print(df)

   name  temp
0  Ella  36.6
1  Maor  40.0
2  Oren  38.2
3   Gal  37.0

   name  temp covid_instructions
0  Ella  36.6         go to work
1  Maor  40.0          stay home
2  Oren  38.2          stay home
3   Gal  37.0         go to work