Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- df = pd.read_csv('/datasets/drink_preferences.csv')
- df = df.dropna(subset=['nonalcoholic_drink'])
- df_female = df[df['gender'] == 'Female']
- # Сгруппируйте и отсортируйте данные
- df_agg = (df_female
- .groupby('nonalcoholic_drink')
- .agg({'resp_id': 'nunique'})
- .sort_values(by='resp_id', ascending=False)
- .reset_index())
- df_agg = pd.DataFrame({'nonalcoholic_drink': ['Coffee', 'Green Tea', 'Black Tea',
- 'Apple Juice', 'Water', 'Gatorade',
- 'Dr. Pepper', 'Coke', 'Pepsi', 'Red Bull'],
- 'resp_id': [25, 22, 21, 19, 19, 15, 12, 8, 7, 4]})
- print(df_agg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement