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.
没有评论:
发表评论