Skip to main content

Read/write gspread worksheets using pandas DataFrames

Project description

gspread-dataframe

https://badge.fury.io/py/gspread-dataframe.svg https://app.travis-ci.com/robin900/gspread-dataframe.svg?branch=master https://img.shields.io/pypi/dm/gspread-dataframe.svg Documentation Status

This package allows easy data flow between a worksheet in a Google spreadsheet and a Pandas DataFrame. Any worksheet you can obtain using the gspread package can be retrieved as a DataFrame with get_as_dataframe; DataFrame objects can be written to a worksheet using set_with_dataframe:

import pandas as pd
from gspread_dataframe import get_as_dataframe, set_with_dataframe

worksheet = some_worksheet_obtained_from_gspread_client

df = pd.DataFrame.from_records([{'a': i, 'b': i * 2} for i in range(100)])
set_with_dataframe(worksheet, df)

df2 = get_as_dataframe(worksheet)

The get_as_dataframe function supports the keyword arguments that are supported by your Pandas version’s text parsing readers, such as pandas.read_csv. Consult your 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:

import pandas as pd
from gspread_dataframe import get_as_dataframe

worksheet = some_worksheet_obtained_from_gspread_client

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

New in version 4.0.0: drop_empty_rows and drop_empty_columns parameters, both True by default, are now accepted by get_as_dataframe. If you created a Google sheet with the default number of columns and rows (20 columns, 1000 rows), but have meaningful values for the DataFrame only in the top left corner of the worksheet, these parameters will cause any empty rows or columns to be discarded automatically.

Formatting Google worksheets for DataFrames

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

import pandas as pd
from gspread_dataframe import get_as_dataframe, set_with_dataframe
from gspread_formatting.dataframe import format_with_dataframe

worksheet = some_worksheet_obtained_from_gspread_client

df = pd.DataFrame.from_records([{'a': i, 'b': i * 2} for i in range(100)])
set_with_dataframe(worksheet, df)
format_with_dataframe(worksheet, df, include_column_header=True)

Installation

Requirements

  • Python 2.7, 3+

  • 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.git
cd gspread-dataframe
python setup.py install

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gspread-dataframe-4.0.0.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

gspread_dataframe-4.0.0-py2.py3-none-any.whl (9.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file gspread-dataframe-4.0.0.tar.gz.

File metadata

  • Download URL: gspread-dataframe-4.0.0.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for gspread-dataframe-4.0.0.tar.gz
Algorithm Hash digest
SHA256 5ca5493478ecae49b833664a06bac8e17b5b4ed0bdf77f551c948f30545860e6
MD5 1ad6c5da578a9cc32ca3101689eae421
BLAKE2b-256 b4bc82a1a8a850468b5db7f894f2f73f690a927a5bf59a67581317c00c0a86d8

See more details on using hashes here.

File details

Details for the file gspread_dataframe-4.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for gspread_dataframe-4.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 19a3c6cd95bf85f8d6c3657227bb921ef36110174d365cc576defe4ed45b6f7d
MD5 e18d158e94a925c28afee77368a506a3
BLAKE2b-256 c92fffb71b19208cf3d3e1e1323716de07bdb46e24c850f2c5627cb8157d9687

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page