SlideShare a Scribd company logo
Jure Čuhalev
Google Sheets in
Python with gspread
Reducing friction between data systems
Problem:


Users love to use Excel-like interface for
data manipulation
Solution:


Introduce multiplayer Excel: Google Sheets
Basic usage of gspread in Python
import gspread


gc = gspread.service_account()


worksheet = gc.open("Summer Potluck (Responses)").sheet1


values_list = worksheet.col_values(6)


print(values_list)


Google Service Account

with access to this Sheet
Use human friendly names
1-indexed because Excel 🙄
['Email', 'mike@example.com', 'maya@example.com',


'romba@example.net', 'boris@example.org']


Column name as part of response
worksheet.get_values()


Grab data as a list of lists
[


["Timestamp", "I'd like to contribute", ".."],


["18/05/2021 09:12:49", "Games", "Yes", "No", "20/05/2021", "mike@example.com"],


...


["18/05/2021 09:13:12", "Food", "Maybe", "Yes", "23/05/2021", "maya@example.com"],


["18/05/2021 09:13:32", "Let me know and I'll try to help", "No", "No",
"22/05/2021","romba@example.net",


],


]
Loading data into pandas
import pandas as pd


import gspread


## https://github.com/robin900/gspread-dataframe


from gspread_dataframe import get_as_dataframe


gc = gspread.service_account()


worksheet = gc.open("Summer Potluck (Responses)").sheet1


df = get_as_dataframe(


worksheet,


parse_dates=True,


usecols=[0,5]


)


print(df.head())
df = get_as_dataframe(


worksheet,


parse_dates=True,


usecols=[0,5]


)


0-indexed, only column 1 and 6
Timestamp Email


0 18/05/2021 09:12:49 mike@example.com


1 18/05/2021 09:13:12 maya@example.com


2 18/05/2021 09:13:32 romba@example.net


3 18/05/2021 09:14:03 boris@example.org


4 NaN NaN
Pandas DataFrame
Writing to Sheets with Pandas
Python library: gspread-pandas
spread.df_to_sheet(df, index=False,


sheet='New Test Sheet', start='A2', replace=True)


spread.update_cells('A1', 'A1', ['Created by:', spread.email])


print(spread)


# <gspread_pandas.client.Spread - User: '<example_user>@gmail.com',


Spread: 'Example Spreadsheet', Sheet: 'New Test Sheet'>
Sheets - Data Validation
Python library: gspread-formatting
validation_rule = DataValidationRule(


BooleanCondition('ONE_OF_LIST',


['OK', 'FAIL', 'TO CHECK']),


showCustomUi=True


)


set_data_validation_for_cell_range(worksheet,


'C2:C100', validation_rule)
Python library: gspread-formatting
validation_rule = DataValidationRule(


BooleanCondition("ONE_OF_RANGE", ["=Buildings!B2:$B30"]),


showCustomUi=True,


)


set_data_validation_for_cell_range(worksheet,


'B2:B100', validation_rule)
Real World Example
Administrative data with different fields
Type of Document
Type of Institution Type of Repository
Type of Education
Python sets up Data Validation Sheets
Drop down data with

correct choices
Data validation
Low amount of training needed

because users already feel comfortable in Excel
Possible next steps
- Callback to apply new data on server


- Use it to generate embeded charts


- PivotTable reports based on imported data


(no code access for business analytics)
Slides and code at jurecuhalev.com
Libraries used: gspread, gspread-dataframe,
gspread-pandas, gspread-formatting
Q/A
Plus:


• interviews with interesting people from IT


• how I use code to automate business


• tips on sourdough bread baking

More Related Content

PDF
Secret of the Machines Kipling
PPTX
Visual round Quiz
PDF
HyperNova Hpyerloop Final Design Report | SpaceX Hyperloop Competition 2017
PPTX
Personality quiz
PPT
a quiz with sound effects,personalities, famous people quiz,personality quiz,...
PDF
Class 2 CBSE Maths Sample Paper Term 2 Model 1
PPTX
primal and dual problem
PPSX
Walt disney failure = inspiration
Secret of the Machines Kipling
Visual round Quiz
HyperNova Hpyerloop Final Design Report | SpaceX Hyperloop Competition 2017
Personality quiz
a quiz with sound effects,personalities, famous people quiz,personality quiz,...
Class 2 CBSE Maths Sample Paper Term 2 Model 1
primal and dual problem
Walt disney failure = inspiration

Similar to Google Sheets in Python with gspread (20)

PDF
Tactical data engineering
PDF
Strategies for refactoring and migrating a big old project to be multilingual...
PDF
Bulletproof Jobs: Patterns For Large-Scale Spark Processing
PDF
Groovy kind of test
PDF
Groovy kind of test
DOCX
Ml all programs
DOCX
ggtimeseries-->ggplot2 extensions
PPT
AIA101.2.Access Queries Accelerated
PDF
Creating Domain Specific Languages in Python
PDF
Advanced Django
PPTX
Google Chart Tools Kanika Garg (10BM60035) Lavanya R. (10BM60042)
PPTX
Google Chart Tools
PPTX
Unit 4_Working with Graphs _python (2).pptx
PDF
Bca sem 6 php practicals 1to12
DOCX
Python Laboratory Programming Manual.docx
PDF
R for you
PPTX
Javascript 1
PPTX
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
PDF
Real-Time Spark: From Interactive Queries to Streaming
PDF
DN 2017 | Multi-Paradigm Data Science - On the many dimensions of Knowledge D...
Tactical data engineering
Strategies for refactoring and migrating a big old project to be multilingual...
Bulletproof Jobs: Patterns For Large-Scale Spark Processing
Groovy kind of test
Groovy kind of test
Ml all programs
ggtimeseries-->ggplot2 extensions
AIA101.2.Access Queries Accelerated
Creating Domain Specific Languages in Python
Advanced Django
Google Chart Tools Kanika Garg (10BM60035) Lavanya R. (10BM60042)
Google Chart Tools
Unit 4_Working with Graphs _python (2).pptx
Bca sem 6 php practicals 1to12
Python Laboratory Programming Manual.docx
R for you
Javascript 1
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
Real-Time Spark: From Interactive Queries to Streaming
DN 2017 | Multi-Paradigm Data Science - On the many dimensions of Knowledge D...
Ad

More from Jure Cuhalev (19)

PDF
Python icecream library
PDF
Up Your Freelancing Game
PDF
DevOps For Solo Developers
PDF
Kaj je cms
PDF
Prevoz.org presentation
PDF
Poke Is The New Greeting Card
PDF
Pimp Your Blog
PDF
Twitter and Alternative reality games
PDF
Personal branding, social media and pretty pictures
ZIP
Pretty Pictures
ZIP
O BarCampih
PPT
Blog Enhancing through Extensions
PDF
Druzbene Vloge
PDF
Druzbeni Mediji Blogres08
PDF
Its Complicated (2)
PDF
It's Complicated
PDF
Web2 Expo San Francisco
PDF
RDFa in ostala spletna semantika
PDF
Odprta Koda in vas Mac
Python icecream library
Up Your Freelancing Game
DevOps For Solo Developers
Kaj je cms
Prevoz.org presentation
Poke Is The New Greeting Card
Pimp Your Blog
Twitter and Alternative reality games
Personal branding, social media and pretty pictures
Pretty Pictures
O BarCampih
Blog Enhancing through Extensions
Druzbene Vloge
Druzbeni Mediji Blogres08
Its Complicated (2)
It's Complicated
Web2 Expo San Francisco
RDFa in ostala spletna semantika
Odprta Koda in vas Mac
Ad

Recently uploaded (20)

PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
DOCX
573137875-Attendance-Management-System-original
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
PPT on Performance Review to get promotions
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
composite construction of structures.pdf
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
additive manufacturing of ss316l using mig welding
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
bas. eng. economics group 4 presentation 1.pptx
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Foundation to blockchain - A guide to Blockchain Tech
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
573137875-Attendance-Management-System-original
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPT on Performance Review to get promotions
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
composite construction of structures.pdf
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Sustainable Sites - Green Building Construction
OOP with Java - Java Introduction (Basics)
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
additive manufacturing of ss316l using mig welding
Model Code of Practice - Construction Work - 21102022 .pdf

Google Sheets in Python with gspread

  • 1. Jure Čuhalev Google Sheets in Python with gspread Reducing friction between data systems
  • 2. Problem: 
 Users love to use Excel-like interface for data manipulation Solution: 
 Introduce multiplayer Excel: Google Sheets
  • 3. Basic usage of gspread in Python
  • 4. import gspread gc = gspread.service_account() worksheet = gc.open("Summer Potluck (Responses)").sheet1 values_list = worksheet.col_values(6) print(values_list) Google Service Account
 with access to this Sheet Use human friendly names 1-indexed because Excel 🙄
  • 5. ['Email', 'mike@example.com', 'maya@example.com', 'romba@example.net', 'boris@example.org'] Column name as part of response worksheet.get_values() Grab data as a list of lists [ ["Timestamp", "I'd like to contribute", ".."], ["18/05/2021 09:12:49", "Games", "Yes", "No", "20/05/2021", "mike@example.com"], ... ["18/05/2021 09:13:12", "Food", "Maybe", "Yes", "23/05/2021", "maya@example.com"], ["18/05/2021 09:13:32", "Let me know and I'll try to help", "No", "No", "22/05/2021","romba@example.net", ], ]
  • 6. Loading data into pandas import pandas as pd import gspread ## https://github.com/robin900/gspread-dataframe from gspread_dataframe import get_as_dataframe gc = gspread.service_account() worksheet = gc.open("Summer Potluck (Responses)").sheet1 df = get_as_dataframe( worksheet, parse_dates=True, usecols=[0,5] ) print(df.head())
  • 7. df = get_as_dataframe( worksheet, parse_dates=True, usecols=[0,5] ) 0-indexed, only column 1 and 6 Timestamp Email 0 18/05/2021 09:12:49 mike@example.com 1 18/05/2021 09:13:12 maya@example.com 2 18/05/2021 09:13:32 romba@example.net 3 18/05/2021 09:14:03 boris@example.org 4 NaN NaN Pandas DataFrame
  • 8. Writing to Sheets with Pandas Python library: gspread-pandas spread.df_to_sheet(df, index=False, sheet='New Test Sheet', start='A2', replace=True) spread.update_cells('A1', 'A1', ['Created by:', spread.email]) print(spread) # <gspread_pandas.client.Spread - User: '<example_user>@gmail.com', Spread: 'Example Spreadsheet', Sheet: 'New Test Sheet'>
  • 9. Sheets - Data Validation
  • 10. Python library: gspread-formatting validation_rule = DataValidationRule( BooleanCondition('ONE_OF_LIST', ['OK', 'FAIL', 'TO CHECK']), showCustomUi=True ) set_data_validation_for_cell_range(worksheet, 'C2:C100', validation_rule)
  • 11. Python library: gspread-formatting validation_rule = DataValidationRule( BooleanCondition("ONE_OF_RANGE", ["=Buildings!B2:$B30"]), showCustomUi=True, ) set_data_validation_for_cell_range(worksheet, 'B2:B100', validation_rule)
  • 13. Administrative data with different fields Type of Document Type of Institution Type of Repository Type of Education
  • 14. Python sets up Data Validation Sheets Drop down data with correct choices Data validation Low amount of training needed because users already feel comfortable in Excel
  • 15. Possible next steps - Callback to apply new data on server - Use it to generate embeded charts - PivotTable reports based on imported data 
 (no code access for business analytics)
  • 16. Slides and code at jurecuhalev.com Libraries used: gspread, gspread-dataframe, gspread-pandas, gspread-formatting Q/A Plus: • interviews with interesting people from IT • how I use code to automate business • tips on sourdough bread baking