I have encounter a problem with the google ads report and I have no clue how to fix it... I use the following code to extract the data from google ads via API call

import sys from googleads import adwords import pandas as pd import pandas as np import io output = io.StringIO() def main(client):   # Initialize appropriate service.   report_downloader = client.GetReportDownloader(version='v201809')   # Create report query.   report_query = (adwords.ReportQueryBuilder()                   .Select('CampaignId', 'AdGroupId', 'Id', 'Criteria',                           'CriteriaType', 'FinalUrls', 'Impressions', 'Clicks',                           'Cost')                   .From('CRITERIA_PERFORMANCE_REPORT')                   .Where('Status').In('ENABLED', 'PAUSED')                   .During('LAST_7_DAYS')                   .Build())   # You can provide a file object to write the output to. For this   # demonstration we use sys.stdout to write the report to the screen.   report_downloader.DownloadReportWithAwql(       report_query, 'CSV', output, skip_report_header=False,       skip_column_header=False, skip_report_summary=False,       include_zero_impressions=True)   output.seek(0)   df = pd.read_csv(output)   df = df.to_csv('results.csv') if __name__ == '__main__':   # Initialize client object.   adwords_client = adwords.AdWordsClient.LoadFromStorage()   main(adwords_client) 

the code works as expected and pulls the data and save it in a CSV file, however, when I access the columns it prints just one column 'CRITERIA_PERFORMANCE_REPORT (Nov 5, 2019-Nov 11, 2019)' when I open the csv file looks like this

result.csv

I have tried to drop the first row with df.drop(df.index[0]) to access the rest of the data however nothing seems to be working. is there any way I can remove the first row or change to use the second row as the columns names which is the result I expected.

thanks in advance

Tag:google-ads-api, python-3.x, pandas

2 comments.

  1. wpercy

    I'm able to eliminate the header there with the following download request:

    report_downloader.DownloadReportWithAwql( report_query, 'CSV', output, skip_report_header=True, skip_column_header=False, skip_report_summary=True, include_zero_impressions=True )

    I think if you include skip_report_header=True, skip_report_summary=True you'll get what you want.

    1. Isaac_R

      outstanding exactly what I was looking for... thanks a lot...

Add a new comment.