Skip to main content

Read/write gspread worksheets using pandas DataFrames

Project description

gspread-dataframe

https://badge.fury.io/py/gspread-dataframe.svg https://travis-ci.org/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)

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.14.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-3.1.0.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gspread_dataframe-3.1.0-py2.py3-none-any.whl (7.1 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: gspread-dataframe-3.1.0.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for gspread-dataframe-3.1.0.tar.gz
Algorithm Hash digest
SHA256 e4640fb34fc01cea3e99c9d7609012952652b6844d6f9b4656d59cb2ded8af6c
MD5 0d93deff5a5e753874b526f0814e67b0
BLAKE2b-256 653a8c42cb2d8d7867f40746d4028c1a7e9f71ded106bd35bfcbeb60f8f9b3a0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gspread_dataframe-3.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for gspread_dataframe-3.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 388a54258b21f7949e5d1f3c66c5bf6566546445d74ae2476f000086c1e82258
MD5 fa5a258808a768e5d31c51f164e8c04d
BLAKE2b-256 9fc8293097de3318e668726f1596cc9c59df5eb30ce274a6ee913dd0c809965f

See more details on using hashes here.

Supported by

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