
Creating Google sheets
Create one folder inside your google drive, give the name as python-test.
Give Share authorization ( Share with people and group ) to Google API service account you are using.
Google API authorization and Share at Part 1 here »
Creating one new File my_sheet1 ( google sheet ) inside python-test directory.
import pygsheets
path='G:\\My drive\\testing\\google-sheet\\creds1.json'
gc=pygsheets.authorize(service_account_file=path)
sh=gc.create('my_sheet1',folder_name='python-test')
set_dataframe
set_dataframe(df, start, copy_index=False, copy_head=True,
extend=False, fit=False, escape_formulae=False, **kwargs)
Options | Details |
df | Pandas DataFrame |
start | Staring Point tuple ( row, column). It is (1,1) in below example |
copy_index | Default False, Copy Index data from DataFrame |
copy_head | True ( default ), column headers of Pandas DataFrame is copied. |
extend | False( default) If required add columns and rows ( see example ) |
fit | False(default), Resize to fit all data in DataFrame if required |
escape_formulae | How to handle formula ( value with = or +- sign ) |
nan | Replace NaN values with |
Create Pandas DataFrame and then store the same inside our google sheets my_sheet1.
wk1=sh[0] # first worksheet
import pandas as pd # importing Pandas library
my_dict={
'NAME':['Ravi','Raju','Alex'],
'ID':[1,2,3],'MATH':[30,40,50],
'ENGLISH':[20,30,40]
}
df = pd.DataFrame(data=my_dict) # creating DataFrame
wk1.set_dataframe(df,(1,1))
← Subscribe to our YouTube Channel here