Skip to content

Instantly share code, notes, and snippets.

View MarkusMueller-DS's full-sized avatar
💯
always learning

Markus Müller MarkusMueller-DS

💯
always learning
View GitHub Profile
@MarkusMueller-DS
MarkusMueller-DS / lambda_new_col.py
Last active October 2, 2020 08:43
Create a new column with a lambda function
# code creates a new column based on the quality of the wine using 6 as a threshold
df['rating'] = df['quality'].apply(lambda x: 'good' if x >= 6 else 'bad')
@MarkusMueller-DS
MarkusMueller-DS / for_loop_dict.py
Last active October 2, 2020 07:55
a for loop which saves the result of a sampling dist in a dict
# from Udemy course: Data Science & Deep Learning for Business
# stratum_white and stratum_red are Data Frames
alcohol_per_wine_type = {}
for stratum, wine_type in [(stratum_white, 'white'), (stratum_red, 'red')]:
sample = stratum['alcohol'].sample(250, random_state = 0) # random sampling on each stratum
alcohol_per_wine_type[wine_type] = sample.mean()
print(alcohol_per_wine_type)