Skip to content

Commit 81ee322

Browse files
committed
added instructions for google sheets
1 parent f4851e5 commit 81ee322

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

doc/source/user_guide/io.rst

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6290,6 +6290,64 @@ More information about the SAV and ZSAV file formats is available here_.
62906290

62916291
.. _io.other:
62926292

6293+
Google Sheets(via Colab)
6294+
--------------------------------
6295+
6296+
Google Colab provides a utility class to read from and write to Google Sheets.
6297+
6298+
Opening and reading from a sheet
6299+
''''''''''''''''''''''''''''''''
6300+
We can open existing sheets by initializing ``sheets.InteractiveSheet`` with either:
6301+
6302+
* the ``url`` parameter, for example https://docs.google.com/spreadsheets/d/1MaOZNCUIe-NzhZ1aI3PgnBcs2TqNTB-AWBSNNcS15KI
6303+
* the ``sheet_id`` parameter for example 1MaOZNCUIe-NzhZ1aI3PgnBcs2TqNTB-AWBSNNcS15KI
6304+
6305+
By default the left-most worksheets will be used, this can be changed by providing either ``worksheet_id`` or ``worksheet_name``.
6306+
6307+
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.
6308+
6309+
.. code-block:: python
6310+
6311+
import pandas as pd
6312+
from google.colab import sheets
6313+
6314+
url = "https://docs.google.com/spreadsheets/d/1MaOZNCUIe-NzhZ1aI3PgnBcs2TqNTB-AWBSNNcS15KI"
6315+
sheet = sheets.InteractiveSheet(url=url,backend="pandas", display=False)
6316+
6317+
df = sheet.as_df()
6318+
6319+
Creating a new sheet
6320+
''''''''''''''''''''''''''''''''''
6321+
6322+
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.
6323+
6324+
.. code-block:: python
6325+
6326+
sheet = sheets.InteractiveSheet(title='colab pandas',backend='pandas',display=False)
6327+
6328+
Writing to a sheet
6329+
''''''''''''''''''''''''''''''''''
6330+
When opening a spreadsheet you can pass your dataframe as the ``df`` parameter to write immediately.
6331+
6332+
.. code-block:: python
6333+
6334+
df = pd.DataFrame({"a": [1,2,3], "b": ["a", "b", "c"]})
6335+
sheet = sheets.InteractiveSheet(df=df, title="colab pandas", backend="pandas")
6336+
6337+
Using the ``update`` method by default clears the sheet and writes the dateframe starting from the topleft corner.
6338+
6339+
.. code-block:: python
6340+
6341+
sheet.update(df)
6342+
6343+
The ``clear`` parameter controls whether or not the sheet is cleared before updating. The ``location`` parameter controls where the data is written.
6344+
6345+
.. code-block:: python
6346+
6347+
sheet.update(df,location="B2")
6348+
sheet.update(df,location=(1,1))
6349+
sheet.update(df,clear=False)
6350+
62936351
Other file formats
62946352
------------------
62956353

0 commit comments

Comments
 (0)