如何在python中绘制和显示数据集的分布?

如何在python中绘制和显示数据集的分布?,python,plot,data-visualization,treemap,Python,Plot,Data Visualization,Treemap,我有一个数据集,它的一小部分如下所示 data = [ ['2018-01-01', 1.323 , 'AI' , 2000,'Communications','Mothers'], ['2018-01-02', 1.525 , 'AI', 1500,'Communications','Mothers'], ['2018-01-03', 1.045 , 'AI' , 500,'Communications','Mothers'], ['

我有一个数据集,它的一小部分如下所示

data = [ ['2018-01-01',  1.323 ,    'AI' ,   2000,'Communications','Mothers'], 
   ['2018-01-02',  1.525 ,    'AI',    1500,'Communications','Mothers'],
   ['2018-01-03',  1.045 ,    'AI' ,    500,'Communications','Mothers'],
   ['2018-01-04',  1.845 ,    'AI' ,    600,'Communications','Mothers'],
  ['2018-01-05',  1.045 ,    'AI' ,    500,'Communications','Mothers'],
   ['2018-01-02',  1.446  ,  'BOC' ,    550,'Pharmaceuticals','JASDAQ Standard'],
   ['2018-01-03',  2.110 ,   'BOC' ,   3201,'Pharmaceuticals','JASDAQ Standard'],
   ['2018-01-04',  2.150 ,   'BOC' ,   5200,'Pharmaceuticals','JASDAQ Standard'],
   ['2018-01-05',  2.810 ,   'BOC' ,   1980,'Pharmaceuticals','JASDAQ Standard'],
   ['2018-01-03',  5.199 ,   'CAT' ,   2000,'Real Estate','Mothers'],
  ['2018-01-06',  4.980 ,   'CAT' ,    450,'Real Estate','Mothers'],
  ['2018-01-07',  4.990 ,   'CAT' ,   3000,'Real Estate','Mothers']]
df = pd.DataFrame(data,columns =['date',  'price', 'ticker',  'volume', 'Sector','Market Division'])
我想说明哪个市场部门有更多的股票,哪个部门有更多的股票。 我尝试了下面的树形图,但没有成功 我该怎么做

import plotly.express as px
import numpy as np

a=df.groupby(['Market Division','Sector']).count()

a["Exchange"] = "Exchange" # in order to have a single root node
fig = px.treemap(a, path=['Exchange', 'Market Division', 'Sector','ticker'], values='ticker')
fig.show()
您可以尝试使用。下面是一个虚拟示例:

导入matplotlib.pyplot作为plt
标签=列表(集合([md代表df中的md['Market Division']]))
图,ax=plt.子批次()
jasdaq=[34343454454]
母亲=[35345645344343]
ax.bar(标签,jasdaq[0],标签='Pharmaceuticals')
ax.bar(标签,jasdaq[1],标签='Communication')
ax.bar(labels,jasdaq[2],label='Real Estate')
ax.bar(标签,母亲[0],标签='Pharmaceuticals')
ax.bar(标签,母亲[1],标签='Communication')
ax.bar(标签,母亲[2],标签='Real Estate')
ax.图例()
plt.show()


您需要首先计算每个市场部门的每个部门,并替换jasdaq和mothers,以获得您想要的真实图。

thank You@Misgevolution,我有近百行,很难手动获取属于特定交易所市场的所有股票代码。您需要编写代码来创建列表。上面的示例仅用于Demonestation。只要打印样式正常,您就应该能够编写代码来创建标记列表。