当我查询 AdWords API 以获取 search volume data and trends through their TargetingIdeaSelector 时使用 Python client library返回的数据如下所示:
(TargetingIdeaPage){
totalNumEntries = 1
entries[] =
(TargetingIdea){
data[] =
(Type_AttributeMapEntry){
key = "KEYWORD_TEXT"
value =
(StringAttribute){
Attribute.Type = "StringAttribute"
value = "keyword phrase"
}
},
(Type_AttributeMapEntry){
key = "TARGETED_MONTHLY_SEARCHES"
value =
(MonthlySearchVolumeAttribute){
Attribute.Type = "MonthlySearchVolumeAttribute"
value[] =
(MonthlySearchVolume){
year = 2016
month = 2
count = 2900
},
...
(MonthlySearchVolume){
year = 2015
month = 3
count = 2900
},
}
},
},
}
这不是 JSON,看起来只是一个困惑的 Python 列表。将月度数据扁平化为具有这种结构的 Pandas 数据框的最简单方法是什么?
Keyword | Year | Month | Count
keyword phrase 2016 2 10
最佳答案
输出是一个 sudsobject。我发现这段代码可以解决问题:
import suds.sudsobject as sudsobject
import pandas as pd
a = [sudsobject.asdict(x) for x in output]
df = pd.DataFrame(a)
Addendum: This was once correct but new versions of the API (I tested 201802) now return a zeep.objects. However, zeep.helpers.serialize_object should do the same trick. link
关于python - AdWords API TargetingIdeaPage 服务返回的数据格式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36432927/