'Creating dataframe from column names list and data which have blank spaces
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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

