Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a python script to manipulate google spreadsheet data

I am able to get the feed from the spreadsheet and worksheet ID. I want to capture the data from each cell.

i.e, I am able to get the feed from the worksheet. Now I need to get data(string type?) from each of the cells to make a comparison and for input.

How exactly can I do that?

like image 634
GeminiDNK Avatar asked Mar 04 '10 06:03

GeminiDNK


People also ask

Can Python interact with Google Sheets?

The motivation for using Python to write to Google Sheets If you use Python with Google Sheets, it is easy to integrate your data with data analysis libraries, such as NumPy or Pandas, or with data visualization libraries, such as Matplotlib or Seaborn.


1 Answers

There's another spreadsheet library worth to look at: gspread. I've used Google's data libary mentioned above and to me the provided api is weird. You need to extract spreadsheet's key to start working with this spreadsheet.

Here it's a way simpler. If you need to fetch the data from a cell you can just open a worksheet and get the value:

g = gspread.login('[email protected]', 'password')

worksheet = g.open('name_of_the_spreadsheet').get_worksheet(0)

# Say, you need A2
val = worksheet.cell(2, 1).value

# And then update
worksheet.update_cell(2, 1, '42') 
like image 128
Warwick Avatar answered Oct 28 '22 03:10

Warwick