0
votes

i have a quick question this is my python code to retrieve data from google analtycs api. it works just fine. i would like now to push the result into maria database running on my local machine. i built alrady the scheme and the table in mysql. i was able to establish the connection with maria db. Can you show me how to push the data stored in to the variable "df" into the database?

import google2pandas from google2pandas import * conn = GoogleAnalyticsQuery(secrets='C:/Users/blabla/OneDrive/MyFiles/Documents/analysis/ga-creds/ga-credsclient_secrets.json', token_file_name='C:/Users/l.longo/OneDrive/MyFiles/Documents/analysis//ga-creds/analytics.dat') query = {\ 'ids' : 'ga:23185143', 'metrics' : 'pageviews', 'dimensions' : ['date', 'pagePath'], 'start_date' : '8daysAgo' }

df, metadata = conn.execute_query(**query) print(df) import mysql.connector as mariadb mariadb_connection = mariadb.connect(user='root', password='xxxxx', database='xxxxxx') cursor = mariadb_connection.cursor()

here you have the results i get from analytics api

enter image description here

1

1 Answers

0
votes

You can use INSERT statement over your mysql connection. Check this question Inserting Data using MySql Connector in Python