Skip to content
Chocolate Data Analysis
  • AI Chat
  • Code
  • Report
  • !pip install -q gspread
    import gspread
    import pandas as pd
    from google.oauth2.credentials import Credentials
    
    # Authenticate with Google Sheets API using service account credentials
    creds = Credentials.from_authorized_user_file('token.json')
    client = gspread.authorize(creds)
    
    # Open the sheet and read the data
    sheet = client.open('Chocolate Database').worksheet("Main Data")
    data = sheet.get_all_records()
    
    # Convert data to Pandas dataframe
    df = pd.DataFrame(data, columns=data[0]).iloc[:, :-1]
    
    # Print the dataframe
    df.head(10)