# Weekly Challenge

Solve the challenge, share your solution and summit the ranks of our Community!
###### IDEAS WANTED

We're actively looking for ideas on how to improve Weekly Challenges and would love to hear what you think!

Submit Feedback
We've recently made an accessibility improvement to the community and therefore posts without any content are no longer allowed. Please use the spoiler feature or add a short message in the message body in order to submit your weekly challenge.

## Challenge #206: Hotel Reservations

Highlighted
16 - Nebula

Solution attached below - both in regular Alteryx and embedded Python.

Spoiler
Highlighted
8 - Asteroid

Some logical sorting of the result would have been useful...

Spoiler

Highlighted
Alteryx Partner

Very basic exercise: Here's my - very straight-forward - take on this.

Spoiler

Highlighted
13 - Pulsar

Here is my solution.

Spoiler
Highlighted
8 - Asteroid
Spoiler
Highlighted
7 - Meteor

This one was fun and timely too...

Highlighted
7 - Meteor

Here's my solution. The Alteryx version was not compatible so used a blank workflow.

Check it out!

Thanks

Highlighted
14 - Magnetar

Fun and fast!

Spoiler

Highlighted
7 - Meteor

In looking at the posted solution I probably could have eliminated a few superfluous steps, but here it is:

Spoiler

Highlighted
16 - Nebula

Update on previous post here: https://community.alteryx.com/t5/Weekly-Challenge/Challenge-206-Hotel-Reservations/m-p/547969#M38582

(forgot to put some detail about the solution)

Spoiler

The Python version uses many of the same techniques as any DataFrame project:

DataFrame Fitering
dfInput = dfInput[dfInput['reservation_status'] == 'Check-Out']

new column based on a function based on other columns.
- Helper function
- Do an apply with the axis set to 1 (rows rather than columns)

def rowFunc(row):
arrivalDate = '{}-{}-{}'.format(row.arrival_date_year, row.arrival_date_month, row.arrival_date_day_of_month)
row.arrivalDate = datetime.strptime(arrivalDate, '%Y-%B-%d')
row.departureDate = datetime.strptime(row.reservation_status_date, '%Y-%m-%d')
row.stayTime = (row.departureDate - row.arrivalDate).days
return row

dfInput = dfInput.apply(rowFunc, axis = 1)

Then some summarising - thanks to @NicoleJohnson  for showing me how to do this
dfGrouped = dfInput.groupby(['arrival_date_month']).stayTime.agg([np.mean, np.count_nonzero])

#SnakingMyWayThruChallenges