Created
January 29, 2019 11:03
-
-
Save elena-roff/d84abaa0fdd7a711144053c9253d8f7f to your computer and use it in GitHub Desktop.
Advanced Pivot table example
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
(pd.pivot_table( | |
direct_roundtrip_flights.query('departure_and_destination in @most_common_dep_dest_pairs'), | |
index=['departure_and_destination', 'type_of_flight', 'departure_time_interval', 'departure_day_of_week'], | |
values='booking_id', | |
aggfunc={'booking_id': np.count_nonzero}) | |
.rename(columns={'booking_id': 'n'}) | |
.sort_values('n', ascending=False) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment