I have this data frame in pandas.
course = Courses.objects.filter(date__date__gte=dateFrom.date(),date__date__lte=dateTo.date()).values('course','price','date')
df_course = pd.DataFrame(course)
df_course['day_of_year'] = df_course.formatted_date.apply(lambda x: x.dayofyear)
dailyMinPrices = df_course.groupby(['hotel', 'day_of_year'])['price'].min()
It return:
Course day_of_year Price
Course 1 154 70.0
155 74.0
156 85.0
157 90.0
158 83.0
159 79.0
160 81.0
161 75.0
162 113.0
163 85.0
164 83.0
Course 2 154 96.0
155 112.0
156 73.0
157 78.0
Course 3 154 99.0
155 74.0
156 78.0
157 70.0
158 94.0
159 82.0
I am trying to convert it to django list or django dict, but It always return:
"dailyMinPrices": [70.0,74.0,85.0,90.0,83.0, 79.0,81.0,75.0,113.0,85.0]
I am trying to get this estructure:
"dailyMinPrices": {'course 1':{['day_of_year':154,'price':70.0], ['day_of_year':154,'price':70.0],['day_of_year':154,'price':70.0]}, 'course 2':{...},'course 3':{...}}
I am trying with:
dailyMinPrices.values.tolist() #Not working
dailyMinPrices.to_dict(), Return errors
I would like to do it without for, because it is a lot of registers.