Skip to content

Instantly share code, notes, and snippets.

@GabrielSGoncalves
Created November 22, 2021 18:20
Show Gist options
  • Save GabrielSGoncalves/1e4d8fd9a5801ff66878d23c94fb8476 to your computer and use it in GitHub Desktop.
Save GabrielSGoncalves/1e4d8fd9a5801ff66878d23c94fb8476 to your computer and use it in GitHub Desktop.
Function for reading Google Sheets open to public
from io import BytesIO
import requests
import pandas as pd
def read_public_sheets(file_url: str) -> pd.DataFrame:
"""Read a publicly available Google Sheets file as a Pandas Dataframe.
Parameters
----------
file_url : str
URL adress to the spreadsheet CSV file.
Returns
-------
pd.DataFrame
Dataframe loaded from the CSV adress.
"""
response = requests.get(file_url)
return pd.read_csv(BytesIO(response.content))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment