the embark town column. We can use the following Python code for that purpose.
import seaborn
df = seaborn.load_dataset("titanic")
df.dropna(inplace=True)
frequency_counts = (df["embark_town"].value_counts()/len(df)).to_dict()
print(frequency_counts)
df["embark_town"] = df["embark_town"].map(frequency_counts)
print(df.head())
The output of the above program will be:
{'Southampton': 0.6318681318681318, 'Cherbourg': 0.35714285714285715, 'Queenstown': 0.01098901098901099}
survived pclass sex age ... deck embark_town alive alone
1 1 1 female 38.0 ... C 0.357143 yes False
3 1 1 female 35.0 ... C 0.631868 yes False
6 0 1 male 54.0 ... E 0.631868 no True
10 1 3 female 4.0 ... G 0.631868 yes False
11 1 1 female 58.0 ... C 0.631868 yes True
[5 rows x 15 columns]








































0 Comments