我特灵使用API提取数据,我有一个来自csv的ID列表,我使用for循环提取每个ID的请求,输出是列表的形式,我尝试将它们转换为DataFrame,它们变成单独的DataFrame,我无法将它们合并为一个,因为它们在for循环内。
The code looks like this:
==================
``
# Read ios id from CSV file
data = pd.read_csv('File.csv')
ios = (data['ios_id'])
ios_data= []
# Convert ios id into a list
for i in ios:
ios_data.append(i)
for id in ios_data:
params = {
"os": "ios",
"app_id": id,
"country": "US",
"search_term": "kid",
"auth_token": AUTH_TOKEN
}
response = requests.get(BASE_URL, params)
# print(response.status_code)
raw = response.json()
feedback = raw['feedback']
if feedback != []:
feedback_dict = feedback[0]
df = pd.DataFrame(feedback_dict)
print(df)
else:
pass
``
输出如下所示:
content version ... country tags
0 So I love tiles of hop it’s fun but I don’t th... 4.4.0 ... US Family
1 So I love tiles of hop it’s fun but I don’t th... 4.4.0 ... US Love it
[2 rows x 9 columns]
content ... tags
0 This game is, well, fantastic and I love how B... ... Ads
1 This game is, well, fantastic and I love how B... ... Family
2 This game is, well, fantastic and I love how B... ... Hate it
3 This game is, well, fantastic and I love how B... ... Inappropriate
4 This game is, well, fantastic and I love how B... ... Love it
5 This game is, well, fantastic and I love how B... ... Strenuousness
[6 rows x 9 columns]
1条答案
按热度按时间vc9ivgsu1#
您可以先创建一个空列表/篮子,然后放入每次迭代/拉取中收集的 Dataframe ,最后在循环之后使用
pandas.concat
创建一个完整的单个 Dataframe 。试试这个:
#输出: