Created
October 18, 2018 22:05
-
-
Save MacHu-GWU/4b6282e2d114382113bfe1159cb590c3 to your computer and use it in GitHub Desktop.
Google Sheet to pandas.DataFrame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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