After executing the cell above, a new file named 'Sample file' will appear in your drive.google.com file list. Your file ID will differ since you will have created a new, distinct file from the example above.

# Download the file we just uploaded.## Replace the assignment below with your file ID# to download a different file.## A file ID looks like: 1uBtlaggVyWshwcyP6kEI-y_W3P8D26szfile_id='target_file_id'importiofromgoogleapiclient.httpimportMediaIoBaseDownloadrequest=drive_service.files().get_media(fileId=file_id)downloaded=io.BytesIO()downloader=MediaIoBaseDownload(downloaded,request)done=FalsewhiledoneisFalse:# _ is a placeholder for a progress object that we ignore.# (Our file is small, so we skip reporting progress.)_,done=downloader.next_chunk()downloaded.seek(0)print('Downloaded file contents are: {}'.format(downloaded.read()))

After executing the cell above, a new spreadsheet will be shown in your sheets list on sheets.google.com.

In [0]:

# Open our new sheet and add some data.worksheet=gc.open('A new spreadsheet').sheet1cell_list=worksheet.range('A1:C2')importrandomforcellincell_list:cell.value=random.randint(1,10)worksheet.update_cells(cell_list)

After executing the cell above, the sheet will be populated with random numbers in the assigned range.

We'll read back to the data that we inserted above and convert the result into a Pandas DataFrame.

(The data you observe will differ since the contents of each cell is a random number.)

In [0]:

# Open our new sheet and read some data.worksheet=gc.open('A new spreadsheet').sheet1# get_all_values gives a list of rows.rows=worksheet.get_all_values()print(rows)# Convert to a DataFrame and render.importpandasaspdpd.DataFrame.from_records(rows)