xxxxxxxxxx
import pandas as pd
# Example DataFrame with a 'smoker' column containing 'yes' and 'no'
data = {'smoker': ['yes', 'no', 'no', 'yes', 'yes', 'no']}
df = pd.DataFrame(data)
# Using the map function to convert 'yes' to 1 and 'no' to 0
df['smoker_encoded'] = df['smoker'].map({'yes': 1, 'no': 0})
print(df)
xxxxxxxxxx
import pandas as pd
# Example DataFrame with a 'smoker' column containing 'yes' and 'no'
data = {'smoker': ['yes', 'no', 'no', 'yes', 'yes', 'no']}
df = pd.DataFrame(data)
# Using the map function to convert 'yes' to 1 and 'no' to 0
df['smoker_encoded'] = df['smoker'].map({'yes': 1, 'no': 0})
print(df)