我对熊猫和Python还不熟悉
我正在尝试从7个列表中创建一个熊猫数据帧。7个列表中的每一个都有以下结构:
[{'date': '2019-12-02', 'gclid': 'EAIaIQobChMIzru7hs6V5gIVC', 'account_id': 85194250, 'account_name': 'T2', 'campaign_name': 'Generic - Exact/Bmm - German', 'adgroup_name': 'bmm', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2276'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobChMIzsL0mdmW5gIVjLT', 'account_id': 85994250, 'account_name': 'T2', 'campaign_name': 'Generic - Exact/Bmm - French', 'adgroup_name': 'exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2056'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobChMIzsfm8-qW5gIVibTtCh2Jx__D_BwE', 'account_id': 8593250, 'account_name': 'T2', 'campaign_name': 'Exact/Bmm - Italian', 'adgroup_name': 'vpn gratis | exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2380'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobChMIzsj0o7GW5gID_BwE', 'account_id': 85931250, 'account_name': 'T2', 'campaign_name': 'Generic - Exact/Bmm - Swedish', 'adgroup_name': 'exact/bmm', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2752'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobYASAAEgKx6fD_BwE', 'account_id': 854250, 'account_name': 'T2', 'campaign_name': 'Exact/BMM - Dutch', 'adgroup_name': 'vpn verbinding | exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2528'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobCVSrTtCh009QTtEAAYASAAEgLx9PD_BwE', 'account_id': 859350, 'account_name': 'T2', 'campaign_name': 'Exact/Bmm - German', 'adgroup_name': 'exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2276'}]
[{'date': '2019-12-02', 'gclid': 'EAIaIQobwefwefwfChMIzru7hs6V5gIVC', 'account_id': 85194250, 'account_name': 'T2', 'campaign_name': 'Generic - Exact/Bmm - German', 'adgroup_name': 'bmm', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2276'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobChMIzsL0mdmW5gIVjLT', 'account_id': 85994250, 'account_name': 'T2', 'campaign_name': 'Generic - Exact/Bmm - French', 'adgroup_name': 'exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2056'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobChMIzsfm8-qW5gIVibTtCh2Jx__D_BwE', 'account_id': 8593250, 'account_name': 'T2', 'campaign_name': 'Exact/Bmm - Italian', 'adgroup_name': 'vpn gratis | exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2380'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobChMIzsj0o7GW5gID_BwE', 'account_id': 85931250, 'account_name': 'T2', 'campaign_name': 'Generic - Exact/Bmm - Swedish', 'adgroup_name': 'exact/bmm', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2752'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobYASAAEgKx6fD_BwE', 'account_id': 854250, 'account_name': 'T2', 'campaign_name': 'Exact/BMM - Dutch', 'adgroup_name': 'vpn verbinding | exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2528'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobCVSrTtCh009QTtEAAYASAAEgLx9PD_BwE', 'account_id': 859350, 'account_name': 'T2', 'campaign_name': 'Exact/Bmm - German', 'adgroup_name': 'exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2276'}]
[{'date': '2019-12-02', 'gclid': 'EAIaIqdfwefwfChMIzru7hs6V5gIVC', 'account_id': 85194250, 'account_name': 'T2', 'campaign_name': 'Generic - Exact/Bmm - German', 'adgroup_name': 'bmm', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2276'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobChMIzsL0mdmW5gIVjLT', 'account_id': 85994250, 'account_name': 'T2', 'campaign_name': 'Generic - Exact/Bmm - French', 'adgroup_name': 'exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2056'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobChMIzsfm8-qW5gIVibTtCh2Jx__D_BwE', 'account_id': 8593250, 'account_name': 'T2', 'campaign_name': 'Exact/Bmm - Italian', 'adgroup_name': 'vpn gratis | exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2380'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobChMIzsj0o7GW5gID_BwE', 'account_id': 85931250, 'account_name': 'T2', 'campaign_name': 'Generic - Exact/Bmm - Swedish', 'adgroup_name': 'exact/bmm', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2752'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobYASAAEgKx6fD_BwE', 'account_id': 854250, 'account_name': 'T2', 'campaign_name': 'Exact/BMM - Dutch', 'adgroup_name': 'vpn verbinding | exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2528'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobCVSrTtCh009QTtEAAYASAAEgLx9PD_BwE', 'account_id': 859350, 'account_name': 'T2', 'campaign_name': 'Exact/Bmm - German', 'adgroup_name': 'exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2276'}]
...
列表中的每个项目有9个键:
'date'
'gclid'
'account_id'
'account_name'
'campaign_name'
'adgroup_name'
'source'
'clicks'
'criteria_id_country'
我正在尝试创建一个dataframe,其中包含这些列,并保存这些列表中的值:
date gclid account_id account_name adgroup_name source clicks criteria_id_country
我正在使用此功能收集数据:
client_accounts = [1,2,3,4,5,6,7]
def get_full_click_list(account, date):
full_list = []
for item in client_accounts:
full_list.append(get_adwords_clicks(item, date))
print(full_list)
get_full_click_list(client_accounts, '2019-12-02')
我的完整清单的结果是这样的:
[[items from 1st query],[items from 2nd query]...[items from 7th query]]
每个查询列表都有以下结构:
[第1..7次查询中的项目]=
[{'date': '2019-12-02', 'gclid': 'EAIaIqdfwefwfChMIzru7hs6V5gIVC', 'account_id': 85194250, 'account_name': 'T2', 'campaign_name': 'Generic - Exact/Bmm - German', 'adgroup_name': 'bmm', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2276'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobChMIzsL0mdmW5gIVjLT', 'account_id': 85994250, 'account_name': 'T2', 'campaign_name': 'Generic - Exact/Bmm - French', 'adgroup_name': 'exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2056'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobChMIzsfm8-qW5gIVibTtCh2Jx__D_BwE', 'account_id': 8593250, 'account_name': 'T2', 'campaign_name': 'Exact/Bmm - Italian', 'adgroup_name': 'vpn gratis | exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2380'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobChMIzsj0o7GW5gID_BwE', 'account_id': 85931250, 'account_name': 'T2', 'campaign_name': 'Generic - Exact/Bmm - Swedish', 'adgroup_name': 'exact/bmm', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2752'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobYASAAEgKx6fD_BwE', 'account_id': 854250, 'account_name': 'T2', 'campaign_name': 'Exact/BMM - Dutch', 'adgroup_name': 'vpn verbinding | exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2528'}, {'date': '2019-12-02', 'gclid': 'EAIaIQobCVSrTtCh009QTtEAAYASAAEgLx9PD_BwE', 'account_id': 859350, 'account_name': 'T2', 'campaign_name': 'Exact/Bmm - German', 'adgroup_name': 'exact', 'source': 'adwords', 'clicks': 1, 'criteria_id_country': 'geoTargetConstants/2276'}
我该如何继续从我的完整列表中提取信息?或者,我如何在每次查询列表时向数据框添加信息
谢谢你的建议
只需这样做:
其中,list of dicts是您拥有的每个dict的列表(基本上是您上面所写列表的总和)
你可以做一个
concat
:更新:如果一次创建一个列表,可以附加到给定的数据帧:
相关问题 更多 >
编程相关推荐