Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从数据帧创建相对频率图_Python_Python 3.x_Pandas_Matplotlib - Fatal编程技术网

Python 如何从数据帧创建相对频率图

Python 如何从数据帧创建相对频率图,python,python-3.x,pandas,matplotlib,Python,Python 3.x,Pandas,Matplotlib,我知道可以使用以下代码从带有matplotlib.pyplot的pandas dataframe列创建直方图: df.plot.hist(y='Distance') 这将创建如下图形: 然而,我要寻找的是一个相对频率的曲线图,表示为总频率的百分比。我还希望图表中有一个300的溢出箱,这样它看起来就像是: 试试这个: orders = [{'number': 1029,'brand':'XPTO','qty':50}, {'number': 3233,'brand':'ABCD',

我知道可以使用以下代码从带有matplotlib.pyplot的pandas dataframe列创建直方图:

df.plot.hist(y='Distance')
这将创建如下图形:

然而,我要寻找的是一个相对频率的曲线图,表示为总频率的百分比。我还希望图表中有一个300的溢出箱,这样它看起来就像是: 试试这个:

orders = [{'number': 1029,'brand':'XPTO','qty':50},
      {'number': 3233,'brand':'ABCD','qty':50},
      {'number': 5455,'brand':'XPTO','qty':50},
      {'number': 1234,'brand':'ABCD','qty':50},
      {'number': 7654,'brand':'TXWZ','qty':50},
      {'number': 8765,'brand':'XPTO','qty':50},
      {'number': 4354,'brand':'TXWZ','qty':50},
      {'number': 9089,'brand':'XPTO','qty':50},
      {'number': 1031,'brand':'XPTO','qty':50}]
orders_df = pd.DataFrame(orders)
series = orders_df['brand'].value_counts() / len(orders_df)
indx = [0,1,2]
plt.bar(indx, series*100)
plt.ylabel('%')
plt.title('Relative fequency')
plt.xticks(indx, series.index)

您可以使用series=orders\u df['brand']。value\u计数(True)自动标准化,无需除以len(orders\u df),因为您需要*100,这些现在是百分比频率