python - AdWords API TargetingIdeaPage 服务返回的数据格式是什么?

标签 python pandas google-ads-api

当我查询 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/

相关文章:

python - Z3:找出变量的所有可能值

python - 如何在给定 ClientID 的情况下使用 MMC 和 python 广告词库获取事件详细信息

python - 从命令行强制 TensorFlow-GPU 使用 CPU

python - Python进程控制的最佳实践

python - Pandas DataFrame 图 : specify column from MultiIndex for secondary_y

针对n变量预测方程的Python模型

java - 我的 AdMob 广告未在 Android Studio 中展示

javascript - 如何使用 AWQL 获取 'Hour and day of the week' 报告

python - 尝试在 Windows 上 pip 安装包时访问被拒绝

python - 有没有办法获得 pandas DataFrame 的几列的 "union"?