Last active
October 19, 2020 00:36
-
-
Save sjtalkar/21681a8f3b2b1e650c195d48206e54ff to your computer and use it in GitHub Desktop.
UsingPandasGroupByInPowerBI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# '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