How to read a google sheet with Python
• 2 minReading a Google sheet is a bit more complex than reading an Excel spreadsheet.
It requires a bit more authentication
We will need to setup
- The script that will get the data from a google spreadsheet
- Give Google Robots access and permission to see our google spreadsheet
- 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
- Where do you run your script
- 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.