Skip to content

Commit f33b8a1

Browse files
committed
added google colab instructions to the docs
1 parent efe1a5c commit f33b8a1

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

doc/source/user_guide/io.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6324,6 +6324,65 @@ More information about the SAV and ZSAV file formats is available here_.
63246324

63256325
.. _io.other:
63266326

6327+
Google Sheets(via Colab)
6328+
--------------------------------
6329+
6330+
Google Colab provides a utility class to read from and write to Google Sheets.
6331+
6332+
Opening and reading from a sheet
6333+
''''''''''''''''''''''''''''''''
6334+
We can open existing sheets by initializing ``sheets.InteractiveSheet`` with either:
6335+
6336+
* the ``url`` parameter, for example https://docs.google.com/spreadsheets/d/1MaOZNCUIe-NzhZ1aI3PgnBcs2TqNTB-AWBSNNcS15KI
6337+
* the ``sheet_id`` parameter for example 1MaOZNCUIe-NzhZ1aI3PgnBcs2TqNTB-AWBSNNcS15KI
6338+
6339+
By default the left-most worksheets will be used, this can be changed by providing either ``worksheet_id`` or ``worksheet_name``.
6340+
6341+
The first time in each session that we use the ``InteractiveSheet`` method we will need to give Colab permission to edit our drive assets on our behalf.
6342+
6343+
.. code-block:: python
6344+
6345+
import pandas as pd
6346+
from google.colab import sheets
6347+
6348+
url = "https://docs.google.com/spreadsheets/d/1MaOZNCUIe-NzhZ1aI3PgnBcs2TqNTB-AWBSNNcS15KI"
6349+
sheet = sheets.InteractiveSheet(url=url,backend="pandas", display=False)
6350+
6351+
df = sheet.as_df()
6352+
6353+
Creating a new sheet
6354+
''''''''''''''''''''''''''''''''''
6355+
6356+
When you don't provide the source of the spreadsheet one will be created for you. The ``title`` parameter can specify the title of the spreadsheet.
6357+
6358+
.. code-block:: python
6359+
6360+
sheet = sheets.InteractiveSheet(title='colab pandas',backend='pandas',display=False)
6361+
6362+
Writing to a sheet
6363+
''''''''''''''''''''''''''''''''''
6364+
When opening a spreadsheet you can pass your dataframe as the ``df`` parameter to write immediately.
6365+
6366+
.. code-block:: python
6367+
6368+
df = pd.DataFrame({"a": [1,2,3], "b": ["a", "b", "c"]})
6369+
sheet = sheets.InteractiveSheet(df=df, title="colab pandas", backend="pandas")
6370+
6371+
Using the ``update`` method by default clears the sheet and writes the dateframe starting from the topleft corner.
6372+
6373+
.. code-block:: python
6374+
6375+
sheet.update(df)
6376+
6377+
The ``clear`` parameter controls wether or not the sheet is cleared before updating. The ``location`` parameter controls where the data is written.
6378+
6379+
.. code-block:: python
6380+
6381+
sheet.update(df,location="B2")
6382+
sheet.update(df,location=(1,1))
6383+
sheet.update(df,clear=False)
6384+
6385+
63276386
Other file formats
63286387
------------------
63296388

@@ -6553,3 +6612,5 @@ The files ``test.pkl.compress``, ``test.parquet`` and ``test.feather`` took the
65536612
24009288 Oct 10 06:43 test_fixed_compress.hdf
65546613
24458940 Oct 10 06:44 test_table.hdf
65556614
24458940 Oct 10 06:44 test_table_compress.hdf
6615+
6616+

0 commit comments

Comments
 (0)