2021年3月17日星期三

to_dict() function makes a list from dataframe instead of OrderedDict

I am trying to convert a dataframe into an OrderedDict. I tried with the 2 options shown below. None of them result an OrderedDict and I don't know why it doesn't work.

Option 1 and 2 result to be lists

sales_data = pd.read_csv ("data/sales-data.csv")  Motorcycles = sales_data.loc[sales_data['PRODUCTLINE'] == 'Motorcycles']  Motorcycles = Motorcycles.sort_values('ORDERID').head(100)    # Option 1  Dict_Motorcycles = Motorcycles.to_dict(into=OrderedDict, orient='records')  type(Dict_Motorcycles)    # Opction 2  a= Motorcycles.to_dict('records')  type(a)  

If I write the code Motorcycles.to_dict('records') it becomes and OrderedDict, but I'm not able to save it.

https://stackoverflow.com/questions/66683408/to-dict-function-makes-a-list-from-dataframe-instead-of-ordereddict March 18, 2021 at 09:06AM

没有评论:

发表评论