I have been trying to convert data obtained from a Google sheet into a pandas dataframe.
My solution works:
header = data[0] # The first row
all_other_rows = data[1:] # All other rows
df = pd.DataFrame(header, columns=all_other_rows)
However, I don't understand why this code failed:
df = pd.DataFrame(data[0], columns=data[1:])
The error initially is "Shape of Values passed is (4, 1), indices imply (4, 4)", but even when resolved according to this answer, by adding brackets around data[0], it takes 5-10 minutes and the df loads incorrectly. What is the difference?
Extra details of this code:
The data was imported with this code:
gc = gspread.authorize(credentials)
wb = gc.open_by_key(spreadsheet_key)
ws = wb.worksheet(worksheet_name)
ws.get_all_values()
Here's sample data:
[['id', 'other_id', 'another_id', 'time_of_determination'],
['63409', '1', '', '2019-11-14 22:01:19.386903+00'],
['63499', '1', '8', '2019-11-14 22:01:19.386903+00'],
['63999', '1', '', '2019-11-14 22:01:19.386903+00'],
['69999', '1', '', '2019-11-14 22:01:19.386903+00']]