1

Using GOOGLEFINANCE() API on Python, I readback response shown in attached snapshot. I would like to arrange this readback response as a dataframe.

Using the code below, I extract the columns and data from response. Do notice that columns, as well as, each row of data has a blank space as its first entry (marked with green arrows in the photo). Next, when I try to make a dataframe df, I get error AssertionError: 7 columns passed, passed data had 26 columns

I think the first 'blank' data is causing some issue. Any suggestion how to overcome this?

Code:

response = service.spreadsheets().values().get(
        spreadsheetId=spreadsheet_id,
        majorDimension='ROWS',
        range='Sheet1'
    ).execute()
columns = response['values'][1]
data = response['values'][2:]
df = pd.DataFrame(data, columns=columns)

enter image description here

Sinha
  • 431
  • 1
  • 5
  • 12

0 Answers0