Skip to content

Commit 46f4fe8

Browse files
committed
created a new tip to connect to a Google sheet using just pandas
1 parent 712d401 commit 46f4fe8

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## This folder shows how to connect to a remote Google sheet securely using Pandas
2+
3+
First, you copy the URL to the Google sheet and make sure its public (i.e it's share setting is set to 'anyone with this link can open').
4+
5+
from the URL e.g :
6+
```sh
7+
https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/edit#gid=############
8+
```
9+
10+
The section between /d/ and /edit is the Google sheet Id, then also take note of the sheet name, make sure there's no spacing in the name, you can use an underscore in place of a white space.
11+
12+
Then follow the script in **main.py**
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pandas as pd
2+
3+
## Load data from the Google sheet directly:
4+
sheet_id = 'abcdefghijklmnopqrstuvxxyz' # replace with your actual sheet id
5+
6+
sheet_name = 'bwhiz_sample_sheet' #replace with your actual sheet name
7+
8+
url = f"https://docs.google.com/spreadsheets/d/{sheet_id}/gviz/tq?tqx=out:csv&sheet={sheet_name}"
9+
10+
#load into a pandas dataframe
11+
df = pd.read_csv(url)

0 commit comments

Comments
 (0)