Leetcode MEDIUM 3087 - Find Trending Hashtags REGEX Explained - Solved by Everyday Data Science

preview_player
Показать описание


SQL Schema:
Create table If Not Exists Tweets (user_id int, tweet_id int, tweet_date date, tweet varchar(100))
Truncate table Tweets
insert into Tweets (user_id, tweet_id, tweet, tweet_date) values ('135', '13', 'Enjoying a great start to the day. #HappyDay', '2024-02-01')
insert into Tweets (user_id, tweet_id, tweet, tweet_date) values ('136', '14', 'Another #HappyDay with good ', '2024-02-03')
insert into Tweets (user_id, tweet_id, tweet, tweet_date) values ('137', '15', 'Productivity peaks! #WorkLife', '2024-02-04')
insert into Tweets (user_id, tweet_id, tweet, tweet_date) values ('138', '16', 'Exploring new tech frontiers. #TechLife', '2024-02-04')
insert into Tweets (user_id, tweet_id, tweet, tweet_date) values ('139', '17', 'Gratitude for today's moments. #HappyDay', '2024-02-05')
insert into Tweets (user_id, tweet_id, tweet, tweet_date) values ('140', '18', 'Innovation drives us. #TechLife', '2024-02-07')
insert into Tweets (user_id, tweet_id, tweet, tweet_date) values ('141', '19', 'Connecting with nature's serenity. #Nature', '2024-02-09')

Pandas Schema:
data = [[135, 13, 'Enjoying a great start to the day. #HappyDay', '2024-02-01'], [136, 14, 'Another #HappyDay with good ', '2024-02-03'], [137, 15, 'Productivity peaks! #WorkLife', '2024-02-04'], [138, 16, 'Exploring new tech frontiers. #TechLife', '2024-02-04'], [139, 17, "Gratitude for today's moments. #HappyDay", '2024-02-05'], [140, 18, 'Innovation drives us. #TechLife', '2024-02-07'], [141, 19, "Connecting with nature's serenity. #Nature", '2024-02-09']]
tweets = pd.DataFrame(data, columns=['user_id', 'tweet_id', 'tweet_date', 'tweet']).astype({'user_id':'Int64', 'tweet_id':'Int64', 'tweet_date':'datetime64[ns]', 'tweet':'object'})

#datascience #mysqltutorials #leetcodesolutions
Рекомендации по теме
Комментарии
Автор

Thanks for sharing this solution. I was wondering why didn't we use the window function to get the top 3 tweet, instead of the limit. In general, how to identify in which cases to use a window function and when not to use a window function? Do you have any generic way of approaching a problem? I'd appreciate it!

cheerfulchai