Skip to content

Instantly share code, notes, and snippets.

@kshirsagarsiddharth
Created March 15, 2022 12:14
Show Gist options
  • Save kshirsagarsiddharth/130738fe10c49e4eb37a9edc33994f00 to your computer and use it in GitHub Desktop.
Save kshirsagarsiddharth/130738fe10c49e4eb37a9edc33994f00 to your computer and use it in GitHub Desktop.
# find the distribution of website sessions in morning, afternoon, evening and night
%%sql
result <<
SELECT
CASE
WHEN HOUR(created_at) BETWEEN 7 AND 12 THEN 'morning'
WHEN HOUR(created_at) BETWEEN 12 AND 16 THEN 'afternoon'
WHEN HOUR(created_at) BETWEEN 16 AND 20 THEN 'evening'
ELSE 'night'
END AS divide,
COUNT(DISTINCT website_session_id) AS sessions
FROM
orders
GROUP BY divide;
result = result.DataFrame()
px.bar(data_frame=result, x = 'divide', y = 'sessions', template='presentation')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment