sophia
sophia

Reputation: 131

gspread get_all_records not returning values for some columns

I'm reading a spreadsheet populated from a form. When I retrieve the data using get_all_records, one of the columns doesn't return values. However, when I use get_all_values, the values are there.

wks = gc.open_by_key('blahblahblah')
worksheet = wks.worksheet('working')
data2 = worksheet.get_all_records(empty2zero=False, head=1)
data = worksheet.get_all_values()

I export the data to JSON and I want the list of dictionaries returned by get_all_records. I can work around it by zipping the header and lists from get all values but it would be nice to just use get_all_records.

Any insight on why get_all_records would return no values for only one of the columns?

Upvotes: 2

Views: 2038

Answers (1)

sophia
sophia

Reputation: 131

Turns out there were two columns with the same name and python uses the column with the highest index value in the header as the key/value pair to use.

I checked this by creating a dict by zipping the header and values. I had two keys with the same name and only the key with the higher index value in the list was added to the dictionary.

Upvotes: 1

Related Questions