我有一个场景,需要可视化以下数据集。
我需要以这样的方式进行绘制,使其可以代表每个类别每年排名前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
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