Spaces:
Sleeping
Sleeping
Create gsheet_test.py
Browse files- gsheet_test.py +22 -0
gsheet_test.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pygsheets
|
2 |
+
import pandas as pd
|
3 |
+
import os
|
4 |
+
#authorization
|
5 |
+
authorization = os.environ.get("Google_cred")
|
6 |
+
gc = pygsheets.authorize(service_account_env_var = authorization)
|
7 |
+
#gc = pygsheets.authorize(service_file='/Users/erikrood/desktop/QS_Model/creds.json')
|
8 |
+
|
9 |
+
# Create empty dataframe
|
10 |
+
df = pd.DataFrame()
|
11 |
+
|
12 |
+
# Create a column
|
13 |
+
df['name'] = ['John', 'Steve', 'Sarah']
|
14 |
+
|
15 |
+
#open the google spreadsheet (where 'PY to Gsheet Test' is the name of my sheet)
|
16 |
+
sh = gc.open('PY to Gsheet Test')
|
17 |
+
|
18 |
+
#select the first sheet
|
19 |
+
wks = sh[0]
|
20 |
+
|
21 |
+
#update the first sheet with df, starting at cell B2.
|
22 |
+
wks.set_dataframe(df,(1,1))
|