-1

I have a pandas dataframe by using this code:

frame['count'] = 1
frame['age_group'] = pd.cut(frame.age, [0,10,20,30,40,50,60,70,80,90,100])

age_grp = frame.pivot_table('count', index='age_group', columns='gender', aggfunc='sum').fillna(0).

and the dataframe looks like this

     gender       F      M
    age_group       
    (0, 10]     0.0     0.0
    (10, 20]    0.0     0.0
    (20, 30]    2.0     0.0
    (30, 40]    6.0     5.0
    (40, 50]    15.0    4.0
    (50, 60]    35.0    24.0
    (60, 70]    47.0    30.0
    (70, 80]    24.0    6.0
    (80, 90]    1.0     2.0
    (90, 100]   0.0     0.0

How can I loop this dataframe properly? im planning to use a double bar chart using chartjs with this data.

*attempting to try this iterate over pandas dataframe in jinja2

{% for key,value in x.iterrows() %}
      <option value="{{ value['id'] }}">{{ value['text'] }}</option>
{% endfor %}

trying to print the boundaries.

Reub
  • 665
  • 2
  • 18
  • 35
  • 1
    what do you mean "loop this dataframe properly"? – MattR Mar 28 '18 at 16:53
  • I loop a pandas series using {% for i,value in cases_gender.iteritems() %} *insert codes* {% endfor %} – Reub Mar 28 '18 at 17:00
  • @thesilkworm when I use to json I cannot view anymore the boundaries of the data? – Reub Mar 28 '18 at 17:04
  • I think I misunderstood what you were trying to do - will remove the to_json comment as I don't think it is what you were looking for. – sjw Mar 28 '18 at 17:06
  • well I can still the data, I think I can do something around it but I dont see the boundaries anymore in the json format – Reub Mar 28 '18 at 17:06

1 Answers1

0

This is what I was looking for.

 {% for key,value in dm_cases_age_grp.iterrows() %}
                                console.log('{{ value['F'] }}')
                                console.log('{{ value['M'] }}')
                                    console.log('{{ key }}')
                            {% endfor %}
Reub
  • 665
  • 2
  • 18
  • 35