I am trying to create a chart by BMI and respective mean of charges. In the lecture, the histogram is plotted in a way that BMI is on the x axis and the count is on the y axis. When I try to get charges on Y axis, I am getting sum of charges. I am trying to get mean of charges instead. Can you please help?

Hey, welcome to the forum.
If I am not wrong you want to get the mean of charges per BMI correct? I think your groupby statement is wrong.
Can you try the code below?

Hi Birajde! Thank you for replying. What I am trying to do is create a histogram chart where on the x axis I have BMI and on Y axis the mean of charges for that BMI. If I just use x=‘bmi’ and y=‘charges’ then it gives sum of charges. Do you know how can I get the mean of charges plotted on y axis respective to BMI on x axis?

Okay, so I am not sure about histogram cause it plots the count of a range/category in a graph. I think line plot might be a better option here. maybe you can use the code given above and plot y_ax.index in x axis and y_ax.values in y-axis in a line plot.