Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.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_Matplotlib_Plotly_Visualization - Fatal编程技术网

在python中的多个分组列上打印图形

在python中的多个分组列上打印图形,python,matplotlib,plotly,visualization,Python,Matplotlib,Plotly,Visualization,我有一个场景,我需要可视化下面的数据集 我需要以这样一种方式绘制,它可以代表每年每个类别的前2名产品 我尝试了子批次,每个子批次代表一个类别,但我每年都努力创建前2名的产品细节 添加以下示例数据: lst = [['Life Insurance', '2012', 'mylife', '80'], ['Life Insurance', '2012', 'greaterlife', '70'], ['Life Insurance', '2013', 'mylife', '50'],

我有一个场景,我需要可视化下面的数据集

我需要以这样一种方式绘制,它可以代表每年每个类别的前2名产品

我尝试了子批次,每个子批次代表一个类别,但我每年都努力创建前2名的产品细节

添加以下示例数据:

lst = [['Life Insurance', '2012', 'mylife', '80'], ['Life Insurance', '2012', 'greaterlife', '70'], 
      ['Life Insurance', '2013', 'mylife', '50'], ['Life Insurance', '2013', 'greaterlife', '40'],
      ['Life Insurance', '2014', 'mylife', '30'], ['Term Insurance', '1999', 'newterm', '300'],
      ['Term Insurance', '1999', 'termexceeded', '210'], ['Term Insurance', '2013', 'newterm', '200'],
      ['Term Insurance', '2013', 'termexceeded', '150'], ['Term Insurance', '2016', 'newterm', '30']] 
    
df = pd.DataFrame(lst, columns =['Category', 'Year', 'Top2 Products', 'amount']) 
df 

你能提供一些样本数据吗?另外,你想要绘制的是什么,仅仅是产品名称还是缺少一些数字列?@tania我想为每年的每个类别绘制前2名产品。这是供您参考的分组数据。我正在根据金额字段查找前2名产品,以防您以某种方式使用它。

Category    Year    Top2 Products   amount
0   Life Insurance  2012    mylife  80
1   Life Insurance  2012    greaterlife 70
2   Life Insurance  2013    mylife  50
3   Life Insurance  2013    greaterlife 40
4   Life Insurance  2014    mylife  30
5   Term Insurance  1999    newterm 300
6   Term Insurance  1999    termexceeded    210
7   Term Insurance  2013    newterm 200
8   Term Insurance  2013    termexceeded    150
9   Term Insurance  2016    newterm 30