Skip to content

Instantly share code, notes, and snippets.

@elena-roff
Created January 29, 2019 11:03
Show Gist options
  • Save elena-roff/d84abaa0fdd7a711144053c9253d8f7f to your computer and use it in GitHub Desktop.
Save elena-roff/d84abaa0fdd7a711144053c9253d8f7f to your computer and use it in GitHub Desktop.
Advanced Pivot table example
(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