1

I have a dataframe of tweet data that is originally like this:

    lang        long        lat                  hashtag country
1         it  -69.940500  18.486700    DaddyYankeeAlertaRoja      DO
2         it  -69.940500  18.486700  QueremosConciertoDeAURA      DO
3         it  -69.940500  18.486700          LoQueDiceLaFoto      DO
4         sv   14.167014  56.041735                    escSE       S

I have converted it into count information sorted by country and hashtag via:

d = pd.DataFrame({'count' : all_tweets.groupby(['country', 'hashtag']).size()}).reset_index()

d=

   country                        hashtag  count
0            A     100DaysofJapaneseLettering      3
1            A                   100happydays      1
2            A              10cities1backpack      2
3            A                       12points      6
...        ...                            ...    ...
848857      ZW                    reflections      1
848858      ZW                        saveKBD      1
848859      ZW                         sekuru      1
848860      ZW                         selfie      2

I ultimately want to plot the top hashtag per country. How do I take the max count for each country in the df and plot it?

Alex Taipale
  • 61
  • 1
  • 7

1 Answers1

0

I realized this question was a bit of a duplicate to Extract row with maximum value in a group pandas dataframe.

I extracted the most popular hashtag with this command:

max = d.iloc[d.groupby(['country']).apply(lambda x: x['count'].idxmax())]
Community
  • 1
  • 1
Alex Taipale
  • 61
  • 1
  • 7