I'm trying to make a boxplot of auto data of mpg per the number of cylinders. This is the code I have
cyls = list(set(np.array(auto.cylinders)))
data = []
for val in cyls:
d = np.array(auto.loc[auto['cylinders'] == val].mpg)
data.append(d)
fig, ax = plt.subplots()
ax.boxplot(data, positions = cyls);
This was done in a jupyter notebook. It works fine, but it feels like kind of a roundabout solution, especially since this is apparently a lot easier in R. Is there a more concise way of doing this?