Skip to content

Instantly share code, notes, and snippets.

@rjurney
Created October 27, 2023 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjurney/b8bc86dbd22004874d61f5faf02c81b4 to your computer and use it in GitHub Desktop.
Save rjurney/b8bc86dbd22004874d61f5faf02c81b4 to your computer and use it in GitHub Desktop.
import gspread
from gspread_dataframe import set_with_dataframe
import pandas as pd
# Assume df_users and df_companies are your DataFrames
df_users = pd.DataFrame({'Name': ['Alice', 'Bob'], 'Profile': ['alice123', 'bob456']})
df_companies = pd.DataFrame({'Company': ['TechCorp', 'BizInc'], 'Industry': ['Tech', 'Finance']})
# Step 1: Authenticate to Google Sheets API
# (You'll need to follow the gspread authentication steps which involve creating a service account and obtaining a JSON credentials file)
gc = gspread.service_account(filename='credentials.json')
# Step 2: Create a new Google Sheet
spreadsheet = gc.create('LinkedIn Data')
# Step 3: Share the sheet with your account (replace 'your-email@example.com' with your email)
spreadsheet.share('your-email@example.com', perm_type='user', role='writer')
# Step 4: Select the default sheet and rename it to 'Users'
sheet = spreadsheet.sheet1
sheet.update_title('Users')
# Step 5: Load the user data into the 'Users' sheet
set_with_dataframe(sheet, df_users)
# Step 6: Add a new sheet named 'Companies'
companies_sheet = spreadsheet.add_worksheet(title='Companies', rows="100", cols="20")
# Step 7: Load the company data into the 'Companies' sheet
set_with_dataframe(companies_sheet, df_companies)
#!/usr/bin/env bash
pip install gspread gspread_dataframe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment