LdM
LdM

Reputation: 704

Getting the date from a comparison of values within two columns through time

I would like to spot dates (so rows) where the number of likes is smaller than retweets. My data looks like

Date               Text    Like     Retweet
28/02/2020         wow!!!   1          0
28/02/2020         I have a baby!!!   1          4
28/02/2020         No words  0          0
...
05/12/2019         I love cooking! 4    2
05/12/2020         Hello world!    1    1 
...

To find the numbers of likes/retweets per date I did as follows:

df.groupby([df.Date])["Like"].sum()
df.groupby([df.Date])["Retweet"].sum()

Now I would like to see when the number of likes is greater than that one of retweet (in the example should be 5/12/2020).

Upvotes: 1

Views: 26

Answers (1)

Quang Hoang
Quang Hoang

Reputation: 150745

You can filter:

grouped = df.groupby('Date')[['Like','Retweet']].sum()
grouped[grouped['Like'] > grouped['Retweet']].index

# similarly
# grouped.query('Like > Retweet').index

Upvotes: 1

Related Questions