0

I want to hydrate a covid-19 tweets id CSV file. I try to follow https://theneuralblog.com/hydrating-tweet-ids/ for the hydration. I'm using Jupyter notebook, running line by line. But there is an error when I code:

for tweet in t.hydrate(open('/Users/peggyleung95/Desktop/FYP/Untitled Folder/corona_tweets_theta.csv')):
    print(tweet['text'])
    print(tweet['id'])
    
    if tweet['place']:
        print(tweet['place']['country'])

An error msg showing:

KeyError Traceback (most recent call last) in 1 t = Twarc(consumer_key, consumer_secret, access_token, access_token_secret) 2 for tweet in t.hydrate(open('/Users/peggyleung95/Desktop/FYP/Untitled Folder/corona_tweets_theta.csv')): ----> 3 print(tweet['text']) 4 print(tweet['id']) 5

KeyError: 'text'

Park
  • 2,446
  • 1
  • 16
  • 25
Peg
  • 9
  • 2

1 Answers1

0

Make sure your for loop is indented correctly:

for tweet in t.hydrate(open('/Users/peggyleung95/Desktop/FYP/Untitled Folder/corona_tweets_theta.csv')):
    print(tweet['text'])
    print(tweet['id'])

    if tweet['place']:
        print(tweet['place']['country'])
Anis R.
  • 6,656
  • 2
  • 15
  • 37