Hi I am using Google Colaboratory (similar to Jupyter Notebook). Does anyone know how to access data from Google Sheets using Google Colaboratory notebook?
Asked
Active
Viewed 3.4k times
2 Answers
15
Loading data from Google Sheets is covered in the I/O example notebook: https://colab.research.google.com/notebook#fileId=/v2/external/notebooks/io.ipynb&scrollTo=sOm9PFrT8mGG

Bob Smith
- 36,107
- 11
- 98
- 91
8
!pip install --upgrade -q gspread
import gspread
import pandas as pd
from google.colab import auth
auth.authenticate_user()
from google.auth import default
creds, _ = default()
gc = gspread.authorize(creds)
worksheet = gc.open('data_set.csv').sheet1
rows = worksheet.get_all_values()
pd.DataFrame.from_records(rows)

Egon
- 3,718
- 3
- 34
- 48

Alon Lavian
- 1,149
- 13
- 14
-
1google sheet has .gsheet extension, when I am following above steps, it is throwing SpreadsheetNotFound error – ratnesh Jul 13 '20 at 13:41
-
@ratnesh, you need to enter the sheet name exactly as it appears in Google sheets. No need for any extensions. In the example above the sheet is actually called 'data_set.csv' – Alon Lavian Jan 07 '21 at 10:08