mutate one column of pandas dataframe code example
Example: pandas mutate new column
import pandas as pd
df = pd.DataFrame({
'name': ['alice','bob','charlie','daniel'],
'age': [25,66,56,78]
})
df.assign(
is_senior = lambda dataframe: dataframe['age'].map(lambda age: True if age >= 65 else False)
).assign(
name_uppercase = lambda dataframe: dataframe['name'].map(lambda name: name.upper()),
).assign(
name_uppercase_double = lambda dataframe: dataframe['name_uppercase'].map(lambda name: name.upper()+"-"+name.upper())
)