Boxes from the counter table in Python

I have a counting table as a dataframe in Python, and I want to build my distribution as boxplot. For instance:.

df=pandas.DataFrame.from_items([('Quality',[29,30,31,32,33,34,35,36,37,38,39,40]), ('Count', [3,38,512,2646,9523,23151,43140,69250,107597,179374,840596,38243])])

I “solved” it by repeating my quality value in her account. But I don't think this is a good way, and my dataframe is getting really big.

There is one insert in R:

ggplot(df, aes(x=1,y=Quality,weight=Count)) + geom_boxplot()

It displays the following: ! Boxplot of R 1

My goal is to compare the distribution of different groups, and it should look like <w640 " Can Python solve this problem too?

+4
source share
1 answer

What are you trying to see here? The box below will return the next drawing.

enter image description here

import matplotlib.pyplot as plt
import pandas as pd
%matplotlib inline
df=pd.DataFrame.from_items([('Quality',[29,30,31,32,33,34,35,36,37,38,39,40]), ('Count', [3,38,512,2646,9523,23151,43140,69250,107597,179374,840596,38243])])
plt.figure()
df_box = df.boxplot(column='Quality', by='Count',return_type='axes')

, , :

plt.figure()
df_hist = plt.hist(df.Quality, bins=10, range=None, normed=False, weights=df.Count)

Histogramme

0

Source: https://habr.com/ru/post/1650131/


All Articles