Last active
October 18, 2020 23:23
-
-
Save sjtalkar/62279587561b62e99d24a109ea11bb63 to your computer and use it in GitHub Desktop.
Usage of Transform in Pandas
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
#Create a GroupBy object | |
df_groups = df.groupby(['Destination City Name', 'Origin State', 'Origin City', 'Unique Carrier']) | |
new_df = df_groups.agg(Total_Flights = ('Flight Date','count')) | |
new_df['Count Delayed Flights'] = df_groups.apply(lambda x : x[x['Arrival Delay'] > 0]['Arrival Delay'].count() ) | |
new_df['Delayed Per Origin'] = new_df.groupby(['Destination City Name', 'Origin State', 'Origin City'])['Count Delayed Flights'].transform('sum') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment