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