我有一个df,看起来像这样,叫做full\u senator\u df:
Official Twitter Senator party
0 SenShelby Richard Shelby Republican
1 lisamurkowski Lisa Murkowski Republican
2 SenDanSullivan Dan Sullivan Republican
我已经编写了一些代码来使用这些数据检索这些参议员的tweet。有没有办法将结果附加到表中,或者将结果作为json而不是当前正在进行的打印?你知道吗
senator_count = 0
num_senators = len(full_senator_df.index)
while senator_count <= num_senators:
senator_official_twitter = full_senator_df['Official Twitter'][senator_count]
tweets = api.user_timeline(screen_name = senator_official_twitter, count = tweet_num, include_rts = True)
for status in tweets:
print(full_senator_df['Senator'][senator_count], status.text, full_senator_df['party'][senator_count])
senator_count += 1
我想你快到了。如果希望保持循环,可以将数据加载到数据帧中,而不是打印。首先定义一个新的数据帧
下面的代码创建了一个新的数据帧(表),其中每个参议员和每个政党都有tweets
输出应该是
相关问题 更多 >
编程相关推荐