Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Read/write Google spreadsheets using pandas DataFrames

License

NotificationsYou must be signed in to change notification settings

robin900/gspread-dataframe

Repository files navigation

gspread-dataframe

https://github.com/robin900/gspread-dataframe/actions/workflows/python-package.yml/badge.svg?branch=master

This package allows easy data flow between a worksheet in a Google spreadsheetand a Pandas DataFrame. Any worksheet you can obtain using thegspread packagecan be retrieved as a DataFrame withget_as_dataframe; DataFrame objects canbe written to a worksheet usingset_with_dataframe:

importpandasaspdfromgspread_dataframeimportget_as_dataframe,set_with_dataframeworksheet=some_worksheet_obtained_from_gspread_clientdf=pd.DataFrame.from_records([{'a':i,'b':i*2}foriinrange(100)])set_with_dataframe(worksheet,df)df2=get_as_dataframe(worksheet)

Theget_as_dataframe function supports the keyword argumentsthat are supported by your Pandas version's text parsing readers,such aspandas.read_csv. Consultyour Pandas documentation for a full list of options. Since the'python' engine in Pandas is used for parsing,only options supported by that engine are acceptable:

importpandasaspdfromgspread_dataframeimportget_as_dataframeworksheet=some_worksheet_obtained_from_gspread_clientdf=get_as_dataframe(worksheet,parse_dates=True,usecols=[0,2],skiprows=1,header=None)

New in version 4.0.0:drop_empty_rows anddrop_empty_columns parameters, bothTrueby default, are now accepted byget_as_dataframe. If you created a Google sheet with the defaultnumber of columns and rows (26 columns, 1000 rows), but have meaningful values for the DataFrameonly in the top left corner of the worksheet, these parameters will cause any empty rowsor columns to be discarded automatically and absent from the returned DataFrame.

Formatting Google worksheets for DataFrames

If you install thegspread-formatting package, you can additionally format a Google worksheet to suit theDataFrame data you've just written. See thepackage documentation for details, but here's a short example using the default formatter:

importpandasaspdfromgspread_dataframeimportget_as_dataframe,set_with_dataframefromgspread_formatting.dataframeimportformat_with_dataframeworksheet=some_worksheet_obtained_from_gspread_clientdf=pd.DataFrame.from_records([{'a':i,'b':i*2}foriinrange(100)])set_with_dataframe(worksheet,df)format_with_dataframe(worksheet,df,include_column_header=True)

Installation

Requirements

  • Python 3 only, for releases 4.0.0 and later
  • Python 2.7 and 3 for releases prior to 4.0.0
  • gspread (>=3.0.0; to use older versions of gspread, use gspread-dataframe releases of 2.1.1 or earlier)
  • Pandas >= 0.24.0

From PyPI

pip install gspread-dataframe

From GitHub

git clone https://github.com/robin900/gspread-dataframe.gitcd gspread-dataframepython setup.py install

About

Read/write Google spreadsheets using pandas DataFrames

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp