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
14 - Magnetar
14 - Magnetar

Alternative solution!

 

 

Spoiler
Continuing on my #SnakingMyWayThruChallenges journey, solved this one in Python (following the same general path that I took with my original Alteryx-only solution... found some cool new tricks with df.query this time, and starting to feel a bit more comfortable with with aggregation functions and manipulating the format of dataframes!). 

WeeklyChallenge206_Python.JPG

PYTHON SCRIPT:

#################################
from ayx import Package

from ayx import Alteryx
import pandas as pd

# Input Alteryx hotel bookings data
df = Alteryx.read("#1")


#################################
# Filter for only those records with reservation status = "Check-Out"
df = df.query('reservation_status == "Check-Out"')

# Format date fields for arrival date and checkout date, and calculate # of days between them
df['arrival_date'] = pd.to_datetime(df['arrival_date_year']+"-"+df['arrival_date_month']+"-"+df['arrival_date_day_of_month'], infer_datetime_format='True')
df['checkout_date'] = pd.to_datetime(df['reservation_status_date'])
df['DaysStayed'] = (df['checkout_date'] - df['arrival_date']).dt.days
df['Number of Reservations'] = 1

# Filter for only those reservations with a duration > 0 days, and format columns
df = df[['arrival_date_month','DaysStayed','Number of Reservations']] \
.query("DaysStayed != '0'") \
.rename(columns = {'arrival_date_month':'Month', 'DaysStayed':'Avg Length of Stay'})


#################################
# Create aggregations of booking data for Avg Length of Stay and Number of Reservations
hotel_bookings = df.groupby('Month', as_index = False).agg({'Avg Length of Stay': "mean", 'Number of Reservations':"sum"})


#################################
Alteryx.write(hotel_bookings,1)


#################################

Cheers!

NJ

 

Highlighted
7 - Meteor

I feel like my solution was mildly convoluted but was able to get the right solution! 

Highlighted
Alteryx Partner
Spoiler
jatterberry_0-1589228505828.png

 

jatterberry_1-1589228515006.png

 

jatterberry_2-1589228523843.png

 

 

Highlighted
8 - Asteroid

fun and quick challenge

Highlighted
Alteryx Partner

Done!

Highlighted
Alteryx Certified Partner

Another challenge down.

 

Spoiler
206 Completed.jpg

Highlighted
6 - Meteoroid

great learning, thanks

Highlighted
8 - Asteroid

My solution. 

Highlighted
Alteryx Partner

Here's my solution

Highlighted
Alteryx
Alteryx

Nice quick one, could shorten it by removing the first filter and the 2nd will take care of the canceled anyway...

 

Spoiler
Challenge206.png