# Trouble understanding how callbacks work with dataframes

**URL:** <https://community.plotly.com/t/trouble-understanding-how-callbacks-work-with-dataframes/21737>\
**Category:** Dash Python\
**Created:** [April 1, 2019, 10:38pm UTC](https://community.plotly.com/t/trouble-understanding-how-callbacks-work-with-dataframes/21737 "2019-04-01T22:38:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![prime90](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@prime90](https://community.plotly.com/u/prime90)\
**Post date:** [April 1, 2019, 10:38pm UTC](https://community.plotly.com/t/trouble-understanding-how-callbacks-work-with-dataframes/21737/1 "2019-04-01T22:38:34Z")

</div>

Hello,

I’m new to dash and I understand the graphing aspect but I’m having a hard time comprehending the creation of callbacks. I’m using a data frame but I keep receiving a key error ‘Month’. However, that data frame key is, in fact, part of the data frame. I’m trying to create a simple paycheck graph that has a weekly radio button which would populate each bar as a weekly sum of my pay and a monthly radio button that would populate each bar as my monthly sum of pay. Attached is a snip-it of code. Any help on this matter would be greatly appreciated. I haven’t come across any examples that use radio buttons and data frames.

```
df_monthly = df_paystub.groupby(['Month']).sum()

dcc.RadioItems(
            id='data-view',
            options=[
                {'label': 'Weekly', 'value': 'Weekly'},
                {'label': 'Monthly', 'value': 'Monthly'},
            ],
            value='Weekly',
            labelStyle={'display': 'inline-block'}
        ),

dcc.Graph(
                id='pay',
            )

@app.callback(dash.dependencies.Output('pay', 'figure'),
              [dash.dependencies.Input('data-view', 'value')])

def update_fig():
    figure={
        'data': [
            go.Bar(
                x = df_monthly['Month'],
                y = df_monthly['CheckTotal'],
                name = 'Take Home Pay',
            ),
                go.Bar(
                x = df_monthly['Month'],
                y = df_monthly['EarnTotal'],
                name = 'Earnings',
            )
        ],
        'layout': go.Layout(
            title = 'Take Home Pay vs. Earnings',
            barmode = 'group',
            yaxis = dict(title = 'Pay (U.S. Dollars)'),
            xaxis = dict(title = 'Date Paid')
        )
    }
    return {'data': [figure]}
```
