我正在尝试标准化获取的 Twitter json 数据。数据是从 Twitter API 获取的,但在对其进行标准化时,数据帧返回空。我打印了传入的数据,因此我确信数据已被获取。 我的代码:
def API_scrap(self, name_list, count_num,auth):
api = tweepy.API(auth)
fail_list = []
user_dfs = {}
count = 0
for name in name_list:
if count % 300 == 0:
print(count)
count += 1
try:
data = api.user_timeline(name, count=count_num, tweet_mode='extended')
user_dfs[name] = pd.DataFrame()
for i in range(len(data)):
jdata = pd.json_normalize(data[i]._json)
user_dfs[name] = user_dfs[name].append(jdata, ignore_index=True)
except:
fail_list.append(name)
continue
print(user_dfs)
return user_dfs, fail_list
我得到的输出是:
0
{871036856434950144: Empty DataFrame
Columns: []
Index: [], 2537962288: Empty DataFrame
Columns: []
Index: [], 2436012276: Empty DataFrame
Columns: []
将 pandas 升级至最新版本