Mary
Mary

Reputation: 359

Transferring data frame to list causing "unsupported type: <class 'str'>" error

I used pandas and gspread to create a data frame based on a working google sheet. After I used df.groupby("date")["value"].sum() function to convert my data frame, I was not able to transfer my data frame to a list, which I was able to do so.

My data frame:

sheetwork = client.open('RMA Daily Workload').sheet1
list_of_work = sheetwork.get_all_records()
dfr = pd.DataFrame(list_of_work, columns = ['Date' , '#Order']) 
dfrname = dfr.rename(columns={"Date": "date", "#Order": "value"})
dfrname["date"] = dfrname["date"].where(dfrname["date"].ne("Past")).ffill()
dfrnow= dfrname.groupby("date")["value"].sum()

After I entered the following command:

rnow = dfrnow.to_dict('records')

I got the error: unsupported type: <class 'str'>

Upvotes: 0

Views: 929

Answers (1)

not_speshal
not_speshal

Reputation: 23166

Converting a pandas.Series to a dictionary does not support the "orient" parameter. Try:

rnow = dfrnow.reset_index().to_dict("records")

Upvotes: 1

Related Questions