Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Sheet to pandas.DataFrame
# -*- coding: utf-8 -*-
"""
- Pip install this: https://github.com/aiguofer/gspread-pandas
- Follow this to setup your Google API credential: https://github.com/aiguofer/gspread-pandas#client-credentials
- Finally you put your credential.json file at ``~/.config/gspread_pandas/google_secret.json``
"""
from gspread_pandas import Spread
# This GSheet exists
spread1 = Spread("husanhe", "Spread Sheet Name 1")
# This GSheet Not, but it automatically created
spread2 = Spread("husanhe", "Spread Sheet Name 2", create_spread=True)
# List all sheet in spread1
for sheet1 in spread1.sheets:
# Read sheet into DataFrame from spread1
df = spread1.sheet_to_df(index=0, header_rows=1, start_row=1, sheet=sheet1.title)
# Write DataFrame to spread2
sheet2 = spread2.df_to_sheet(df, index=False, sheet=sheet1.title, replace=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment