Last active
October 20, 2021 00:26
-
-
Save lakshay-arora/a7aee14b6e3a8296c6b100d49cd86031 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add a sheet with 20 rows and 2 columns | |
sheet.add_worksheet(rows=20,cols=2,title='runs') | |
# get the instance of the second sheet | |
sheet_runs = sheet.get_worksheet(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get the total number of columns | |
sheet_instance.col_count | |
## >> 26 | |
# get the value at the specific cell | |
sheet_instance.cell(col=3,row=2) | |
## >> <Cell R2C3 '63881'> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get the instance of the Spreadsheet | |
sheet = client.open('commentary data') | |
# get the first sheet of the Spreadsheet | |
sheet_instance = sheet.get_worksheet(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# convert the json to dataframe | |
records_df = pd.DataFrame.from_dict(records_data) | |
# view the top records | |
records_df.head() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get all the records of the data | |
records_data = sheet_instance.get_all_records() | |
# view the data | |
records_data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sheet_runs.insert_rows(runs.values.tolist()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sheet_instance = sheet.get_worksheet(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# importing the required libraries | |
import gspread | |
import pandas as pd | |
from oauth2client.service_account import ServiceAccountCredentials |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define the scope | |
scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive'] | |
# add credentials to the account | |
creds = ServiceAccountCredentials.from_json_keyfile_name('add_json_file_here.json', scope) | |
# authorize the clientsheet | |
client = gspread.authorize(creds) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# number of runs by each batsman | |
runs = records_df.groupby(['Batsman_Name'])['Runs'].count().reset_index() | |
runs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define the scope | |
scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive'] | |
# add credentials to the account | |
creds = ServiceAccountCredentials.from_json_keyfile_name('My Sample Project-61da96a5184b.json', scope) | |
# authorize the clientsheet | |
client = gspread.authorize(creds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment