Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions 130_article_views_i.py
Original file line number Diff line number Diff line change
@@ -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'})
8 changes: 8 additions & 0 deletions 131_invalid_tweets.py
Original file line number Diff line number Diff line change
@@ -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']]