Skip to content

Instantly share code, notes, and snippets.

@sjtalkar
Last active October 19, 2020 00:36
Show Gist options
  • Save sjtalkar/21681a8f3b2b1e650c195d48206e54ff to your computer and use it in GitHub Desktop.
Save sjtalkar/21681a8f3b2b1e650c195d48206e54ff to your computer and use it in GitHub Desktop.
UsingPandasGroupByInPowerBI
# 'dataset' holds the input data for this script
import pandas as pd
df_groups = dataset.groupby(['Destination City Name', 'Origin State', 'Origin City', 'Unique Carrier'])
final_df = df_groups.agg(Total_Flights = ('Flight Date','count'))
final_df['Count of Delayed Flights'] = df_groups.apply(lambda x : x[x['Arrival Delay'] > 0]['Arrival Delay'].count() )
final_df = final_df.reset_index()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment