- Notifications
You must be signed in to change notification settings - Fork24
Read/write Google spreadsheets using pandas DataFrames
License
robin900/gspread-dataframe
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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, bothTrue
by 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.
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)
- 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
pip install gspread-dataframe
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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.