Google Sheets to DataFrame
This Python module provides a simple interface to connect to Google Sheets and retrieve data as a pandas DataFrame. It uses the gspread
library to handle Google Sheets API interactions and pandas
for data manipulation.
Prerequisites
Ensure you have the following Python libraries installed:
gspread
pandas
oauth2client
You can install them using pip:
pip install gspread pandas oauth2client
Google Sheets API Setup
- Go to the Google Cloud Console.
- Create a new project (or select an existing one).
- Enable the Google Sheets API and Google Drive API for the project.
- Create credentials for a Service Account and download the JSON key file.
- Share your Google Sheet with the email address in the JSON key file.
Usage
-
Save your Service Account credential JSON file in your project directory.
-
Use the Connect class to fetch data from your Google Sheet:
from sheetconnect import Connect
credential = 'path/to/your/credential.json'
sheet = 'Your Google Sheet Name'
sheet_name = 'Sheet1'
dataframe = Connect.GetDF_Sheet(credential, sheet, sheet_name)
print(dataframe)
Replace 'path/to/your/credential.json', 'Your Google Sheet Name', and 'Sheet1' with your actual file path, Google Sheet name, and worksheet name.
Acknowledgements