How to read a google sheet with Python

2 min readDataGetting Started
7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Reading a Google sheet is a bit more complex than reading an Excel spreadsheet.

Read Excel spreadsheet using python
I bet that your daily work require work with spreadsheet. You might want to read an excel spreadsheet using Python. The best library when dealing with spreadsheet is by far the pandas[https://pandas.pydata.org/docs/index.html] library So here is the code : import pandas as pddf = pd.read_excel…

It requires a bit more authentication

We will need to setup

  1. The script that will get the data from a google spreadsheet
  2. Give Google Robots access and permission to see our google spreadsheet
  3. Install the correct libraries to deal with google authentication

We will need to

  • Create a project on google console
  • Create credentials (Service account)
  • Create an API key (download json file)
  • Get the service account email and share google sheet with it (role : editor)
  • Copy the Google Spreadsheet Id
  • Put the worksheet name as well
  • Execute your script

Where should I put my file ?

What usually matter when dealing with path is

  1. Where do you run your script
  2. Where is your excel file

Usually if you keep them in the same directory like so‌

current_dir/
├── my_file.xslx
└── my_python_script.py

The following code should work‌

import pandas as pd
df = pd.read_excel("./my_file.xslx") # Path ./ means current directory

In case you don't have the pandas library

Open your terminal and type in :‌

pip3 install pandas

It will use pip3 package manager to install the pandas library

Going further

If you want to go to the next level with your Python skill, I have a course that covers what most of the people use Python for.

The best part is that it's free.

Turbocharge your workflow with Python TODAY!

A free short-course that covers all the Python that most practitioners use. Straight to the point, no BS.

GET THE COURSE!
7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.