How To Pull Data From the Adwords API and put into a Pandas Dataframe
So I was able to find out the answer to my own question if anybody is curious or had the same problem I did. I had to import io
and wrote the output from the adwords query to a string that I named output
. I then used the seek()
method to start from the beginning and read that using pandas read_csv
.
from googleads import adwords
import pandas as pd
import numpy as np
import io
# Define output as a string
output = io.StringIO()
# Initialize appropriate service.
adwords_client = adwords.AdWordsClient.LoadFromStorage()
report_downloader = adwords_client.GetReportDownloader(version='v201710')
# Create report query.
report_query = ('''
select Date, HourOfDay, Clicks
from ACCOUNT_PERFORMANCE_REPORT
during LAST_7_DAYS''')
# Write query result to output file
report_downloader.DownloadReportWithAwql(
report_query,
'CSV',
output,
client_customer_id='xxx-xxx-xxx', # denotes which adw account to pull from
skip_report_header=True,
skip_column_header=False,
skip_report_summary=True,
include_zero_impressions=False)
output.seek(0)
df = pd.read_csv(output)
df.head()