Skip to content

Instantly share code, notes, and snippets.

@ericness
Created August 19, 2018 22:45
Show Gist options
  • Save ericness/64973b87b77f88d948607412dc59f44a to your computer and use it in GitHub Desktop.
Save ericness/64973b87b77f88d948607412dc59f44a to your computer and use it in GitHub Desktop.
Builds a MultiIndex of customer and date combinations
unique_customers = daily_orders.index.unique(level='customer')
date_range = pd.DatetimeIndex(
start=datetime(2018, 1, 1),
end=datetime(2018, 1, 10),
freq='D'
)
customer_date_index = (
pd.MultiIndex
.from_product(
iterables=[unique_customers, date_range],
names=['customer', 'order_date']
)
)
print(customer_date_index.values[:5])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment