append_table() : Adding list or CSV data to Google sheets

pygsheets append_table()

Adding data from list, csv and excel file to Google sheet by append_table() in pygsheets

Data will be added to next row (or column ) of the table. ( Here row id or row number of the locations is not required )
append_table(values, start='A1', end=None, dimension='ROWS',
valuesData List to be added
startStaring Point of top left cell ( 'A5')
endBottom right cell
dimensionThe way the value will be added, (Default : ROWS) ,ROWS or COLUMNS( See the example below ).
overwriteIf True the data will be overwritten
Connect to googel drive and open the file (more on connection & authorization)
import pygsheets
path='G:\\My drive\\testing\\google-sheet\\creds1.json'
Adding one row of data
append_table() with start option

Using List


Using a list with loop

for data in l1:
    wk1.append_table(data,start='A2', end=None, 
            dimension='ROWS', overwrite=False)
By using loop we can add conditions and change the data based on required logic.
append_table() with a list of data

Using CSV file

Download the sample CSV file from here. We kept the file in our local system and updated the path below.
path="D:\\my_data\\student.csv" # sample CSV file, use your path
#headings = next(fob) # removing header row
for rec in fob:
append_table() with data from CSV file
In above code we have not used Pandas DataFrame. We can create the DataFrame by using Pandas read_csv() and then use the set_dataframe() to add data to google sheet.
import pandas as pd
path="D:\\my_data\\student.csv" # sample CSV file, use your path
wk1.set_dataframe(df,(3,1))# Place DataFrame from row 3 column 1
append_table() using set_dataframe()

Using Excel file

Download the same student.xlsx file from here. We used read_excel() to create the DataFrame.
import pandas as pd
path="D:\\my_data\\student.xlsx" # sample Excel file, use your path
wk1.set_dataframe(df,(3,1)) # Place DataFrame from row 3 column 1

Using insert_row()

We should use insert_row() when we row number is available. At a perticular location the data can be added. This is the main difference between insert_row() and append_table()
Pygsheets and google API authorization get_as_df()
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2023 All rights reserved worldwide Privacy Policy Disclaimer