2

I have a pandas dataframe like below:

Group    id    Count
G1        412   52
G1        413   34
G2        412   2832
G2        413   314

I am trying to build a pie chart in Python – for each Group and id, I need to display the respective count. It should have two splits - one for Group and other for Id. Outer circle should be Group and inner circle should be id. Just started with the visualisation, wondering whether there is a python library that can do this.

Is this requirement be achieved using bar charts?

gabra
  • 9,484
  • 4
  • 29
  • 45
user3447653
  • 3,968
  • 12
  • 58
  • 100
  • I dont think so. For each slice of Group, there should be two slices. For example, let first slice in Pie chart be for G1, inside that it should two sub slices, one for 412 and another for 413. – user3447653 Sep 06 '16 at 16:11

3 Answers3

1

Have you checked out plotly?

Pie Chart Specific: Pie Charts with Plotly

I will say you do have to make an account but its free and easy.

MattR
  • 4,887
  • 9
  • 40
  • 67
1

Panda also integrates with matplotlib, which is somewhat ugly but very convient. http://pandas.pydata.org/pandas-docs/stable/visualization.html#pie-plot

Some complicated examples Hierarchic pie/donut chart from Pandas DataFrame using bokeh or matplotlib

My experience is that you have to do a lot of configuration if you want to have a basic DIY chart with python. Maybe the best approach for you is one of following choices: 1) try plotly if data is not sensitive 2) use excel and integrate python with the chart in excel, which may save you a lot of time because people can be familiar with excel chart templates easily. 3) DIY by yourself, currently , Bokeh, matplotlib , seaborn are under your consideration if you just want to do something simple.

Community
  • 1
  • 1
Hao Wang
  • 43
  • 9
0

Here's what's required if you use pyexcel and pyexcel-pygal:

>>> import pyexcel as p
>>> sheet = p.get_sheet(file_name='test.csv', delimiter='\t')
>>> sheet
test.csv:
+-------+-----+-------+
| Group | id  | Count |
+-------+-----+-------+
| G1    | 412 | 52    |
+-------+-----+-------+
| G1    | 413 | 34    |
+-------+-----+-------+
| G2    | 412 | 2832  |
+-------+-----+-------+
| G2    | 413 | 314   |
+-------+-----+-------+
>>> sheet.transpose()
>>> sheet
test.csv:
+-------+-----+-----+------+-----+
| Group | G1  | G1  | G2   | G2  |
+-------+-----+-----+------+-----+
| id    | 412 | 413 | 412  | 413 |
+-------+-----+-----+------+-----+
| Count | 52  | 34  | 2832 | 314 |
+-------+-----+-----+------+-----+
>>> sheet.name_rows_by_column(0)
>>> sheet.row['Group']
['G1', 'G1', 'G2', 'G2']
>>> p.save_as(array=[sheet.row['Group'], sheet.row['Count']], dest_chart_type='pie', dest_file_name='group_pie.svg')

group_pie.svg

>>> p.save_as(array=[sheet.row['id'], sheet.row['Count']], dest_chart_type='pie', dest_file_name='id_pie.svg')

id_pie.svg

chfw
  • 4,502
  • 2
  • 29
  • 32