0

我想为 covid-19 推文 ID CSV 文件补充水分。我尝试关注https://theneuralblog.com/hydrating-tweet-ids/进行补水。我正在使用 Jupyter 笔记本,逐行运行。但是当我编码时出现错误:

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'])

错误消息显示:

1 t = Twarc(consumer_key,consumer_secret,access_token,access_token_secret)中的 KeyError Traceback(最近一次通话)2 t.hydrate 中的推文(打开('/Users/peggyleung95/Desktop/FYP/Untitled Folder/corona_tweets_theta.csv') ): ----> 3 打印(tweet['text']) 4 打印(tweet['id']) 5

键错误:'文本'

4

1 回答 1

0

确保您的 for 循环正确缩进:

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'])
于 2022-02-20T15:08:48.530 回答