-3

I have a link to a google spreadsheet that I do not own, but have view access to. Is there a way to get the data in that spreadsheet into the google colab notebook that I am using?

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
john wick
  • 73
  • 9

1 Answers1

1

You should be able to retrieve the content of a Sheet with View Only access in gspread by using open_by_key() or open_by_url().

Example:

Test Sheet:

enter image description here

Google Colab:

!pip install --upgrade -q gspread

import gspread
import pandas as pd
from google.colab import auth
from google.auth import default
auth.authenticate_user()
creds, _ = default()

gc = gspread.authorize(creds)
# sh = gc.open_by_url("Insert Sheet URL here")
sh = gc.open_by_key("Insert Sheet key here")
worksheet = sh.worksheet("Sheet1")
rows = worksheet.get_all_values()
pd.DataFrame.from_records(rows)

Result:

enter image description here

Reference:

Nikko J.
  • 5,319
  • 1
  • 5
  • 14
  • This question is in the close vote review queue, and you can review it [here](https://stackoverflow.com/review/close/31475938). – karel Apr 07 '22 at 09:14