From fe14abc6ee80dc2d4a784b1d776588fb09f2be9c Mon Sep 17 00:00:00 2001 From: Radhika Tekade Date: Mon, 3 Mar 2025 22:24:47 -0800 Subject: [PATCH 1/2] Create 130_article_views_i --- 130_article_views_i.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 130_article_views_i.py diff --git a/130_article_views_i.py b/130_article_views_i.py new file mode 100644 index 0000000..4006ee9 --- /dev/null +++ b/130_article_views_i.py @@ -0,0 +1,10 @@ +# Filter the DF to only include rows where the author_id == viewer_id. +# Remove duplicate author_id entries and sort the results before returning the final DF. + +import pandas as pd + +def article_views(views: pd.DataFrame) -> pd.DataFrame: + df = views.drop(views[views['author_id'] != views['viewer_id']].index) + df.drop_duplicates(subset=['author_id'], inplace = True) + df.sort_values(by=['author_id'], inplace = True) + return df[['author_id']].rename(columns = {'author_id': 'id'}) \ No newline at end of file From c7efa40d20bffcb29bf439f0c58eaaf70fb6b118 Mon Sep 17 00:00:00 2001 From: Radhika Tekade Date: Mon, 3 Mar 2025 22:25:04 -0800 Subject: [PATCH 2/2] Create 131_invalid_tweets --- 131_invalid_tweets.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 131_invalid_tweets.py diff --git a/131_invalid_tweets.py b/131_invalid_tweets.py new file mode 100644 index 0000000..94ee771 --- /dev/null +++ b/131_invalid_tweets.py @@ -0,0 +1,8 @@ +# Give tweets where the len(content) > 15. +# Finally, return a DataFrame containing only the 'tweet_id'. +import pandas as pd + +def invalid_tweets(tweets: pd.DataFrame) -> pd.DataFrame: + isValid = tweets['content'].str.len() > 15 + df = tweets[isValid] + return df[['tweet_id']] \ No newline at end of file