logo
Loading...

用 Python 將資料上傳至 Google Sheets - 快速入門、零成本!用 Looker Studio 輕鬆打造專業戰情面板 - Cupoy

重要知識點 為何需要學習如何用 Python 把資料上傳至 Google Sheets 學習 Pygsheets 實戰演練:抓取 Youbike2.0 資料並上傳至 Google Sheets 為...

重要知識點 為何需要學習如何用 Python 把資料上傳至 Google Sheets 學習 Pygsheets 實戰演練:抓取 Youbike2.0 資料並上傳至 Google Sheets 為何需要學習如何用 Python 把資料上傳至 Google Sheets Looker Studio 需要透過雲端資料儲存服務,才能不僅達到資料輸入,同時有自動化更新資料等功能 Google Sheets 是雲端資料儲存服務中,少數中不需要額外收費的軟體服務 儘管藉由 Google Sheets 會讓 Looker Studio 資料載入時間變長,但只有沒有載入速度要求,Google Sheets 也已經是能夠被使用的狀態 在 XXX 單元中,我們學會如何使用第三方插件自動化地載入資料,在本單元中為因應資料結構複雜,將說明如何藉由 Python 上傳資料至 Google Sheets 圖片來源:6 SIMPLE STEPS TO GET YOUR DATA READY FOR LOOKER STUDIO 學習 Pygsheets 向 Google Cloud Platform 申請 Google Sheets API 將 GCP 服務帳戶予以 Google Sheets 與 Google Sheets 建立連線 import pygsheets # 使用你的憑證檔案進行認證 gc = pygsheets.authorize(service_file='path/to/your/credentials.json') # 打開 Google Sheets 文件 spreadsheet = gc.open('Your Google Sheet Name') 選擇分頁 # 選擇第一個分頁 worksheet = spreadsheet.sheet1 # 或者選擇特定名稱的分頁 worksheet = spreadsheet.worksheet_by_title('Sheet1') 上傳資料 # 上傳資料 data = [ ["Name", "Age", "City"], ["Alice", 30, "New York"], ["Bob", 25, "Los Angeles"], ["Charlie", 35, "Chicago"] ] # 將資料上傳到 A1 起始的範圍 worksheet.update('A1', data) 抓取資料 # 抓取資料 data = worksheet.get_values('A1', 'C4') # 顯示抓取到的資料 for row in data: print(row) # 若想要抓取整張表格 df = worksheet.get_as_df() 實戰演練:抓取 Youbike2.0 資料並上傳至 Google Sheets 知識點回顧 參考資料