Reputation: 10213
I have a Pandas dataframe containing tweets. I want to count the number of tweets that have been retweeted. This code does not work
tweets_retweeted = twitter.apply(lambda x:True if x.retweet_count > 0 else False)
count_of_tweets_retweeted = len(tweets_retweeted[tweets_retweeted == True].index)
The error message I get is
KeyError: ('retweet_count', 'occurred at index created_at')
Upvotes: 0
Views: 237
Reputation: 1486
Without having the ability to recreate your example, there are a few things that could be going on.
Also, just a best practice (in my humble opinion) is to not reference column names with the dot notation. Try to use the bracket notation to differentiate between column names and methods.
Upvotes: 1
Reputation: 7224
Can you do:
j = twitter['retweet_count'] > 0
j.value_counts()
Upvotes: 0