【问题标题】:Python update google sheet from local csv problemPython 从本地 csv 问题更新 google sheet
【发布时间】:2021-08-06 05:44:12
【问题描述】:

我是python的初学者。 我已经成功地将脚本放在一起,从一些硬编码值更新我的谷歌表

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

但是当我尝试从本地 csv 文件更新时,

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

我可以看到在我的终端中运行的 csv 文件数据,但它没有更新谷歌表格。 你能帮我看看我错过了什么吗? 提前谢谢你。

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()

【问题讨论】:

    标签: python csv google-sheets


    【解决方案1】:

    我找到了答案 here 。 感谢 Stack Overflow 和所有贡献者。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-08
      • 2019-11-17
      • 1970-01-01
      • 2015-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多