0

I am a beginner in python. I have successfully put together the script to update my google sheet from some hard coded values

Test1 = [["1/1/2020",4000],["4/4/2020",3000],["7/12/2020",'salah4-tiga1000']]

But when I try to update from a local csv file,

Test2 = pd.read_csv(ordersCSV).to_json()

I can see the csv file data running in my terminal, but it is not updating the google sheet. Can you help me to see what I missed please. Thank you in advance.

from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials
from google.oauth2 import service_account
from oauth2client.transport import request

from pprint import pprint

from numpy import greater
import pandas as pd
from pandas.core import series
from pandas.core.indexes.base import Index
from pyasn1.type.univ import Null


SERVICE_ACCOUNT_FILE = 'drfruit4.json'
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']

creds = None
creds = service_account.Credentials.from_service_account_file(
        SERVICE_ACCOUNT_FILE, scopes=SCOPES)

SPREADSHEET_ID = '1rpgVUAmLojG1_U2SRQ_x9vQGI16mEYiOCGcZLrIRZOQ'

service = build('sheets', 'v4', credentials=creds)

# Call the Sheets API
sheet =service.spreadsheets()
result = sheet.values().get(spreadsheetId=SPREADSHEET_ID,
                            range="Detail_Exp_SiteGiant_via_Python!A1:Z1100").execute()

values = result.get('values',[])

Test1 = [["1/1/2020",4000],["4/4/2020",3000],["7/12/2020",'salah4-tiga1000']]

ordersCSV = r'Ready4Sofia.csv'
Test2 = pd.read_csv(ordersCSV).to_json()

request = sheet.values().update(spreadsheetId=SPREADSHEET_ID,
                                range="Detail_Exp_SiteGiant_via_Python!A1", valueInputOption="USER_ENTERED", body={'values':Test2}).execute()

1 Answer 1

0

I have found the answer here . Thanks to Stack Overflow and all the contributors.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.