Question: I need to call a function when modal close. My code as follows,

```
function openModal(divName) {
        $("#"+divName+"Modal").modal({
        overlayClose: false,
        closeHTML: "<a href='#' title='Close' class='modal-close'>X</a>",
        onShow: function (dialog) {
            $('#simplemodal-container').css({ 'width': 'auto', 'height': 'auto', 'padding-bottom': '1000px' });
            var tmpW = $('#simplemodal-container').width() / 2
            var tmpH = $('#simplemodal-container').height() / 2
            $('#simplemodal-container').css({ 'margin-left': tmpW * -1, 'margin-top': tmpH * -1 });
            },
        close:onClose,
        onClose: ModalClose(),
        opacity: 50,
        persist: true
    });
}

```

I tried two ways to call a function as follows, but both not working

1st way

```
function onClose() {
   alert('called');
}

```

2nd way

```
$('.resetbutton').click(function () {
   alert('called');
}

```

Answer: 
For `Grouper` need datetimes, so format of datetimes is changed by [`MultiIndex.set_levels`](http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.MultiIndex.set_levels.html) after aggregation and also added `closed='left'` for left closing bins:

```
df1['date'] = pd.to_datetime(df1['date']) 

df2 = df1.groupby([pd.Grouper(key='date', freq='W-MON', closed='left'), 
                   'Company', 
                   'Email'])['Email'].count()

new = ((df2.index.levels[0] - pd.to_timedelta(7, unit='d')).strftime('%B%d') + ' - '+  
        df2.index.levels[0].strftime('%B%d') )
df2.index = df2.index.set_levels(new, level=0)

print (df2)
date                   Company  Email      
October07 - October14  abc      mr1@abc.com    2
                                mr2@abc.com    1
                       def      mr1@def.com    1
                       xyz      mr1@xyz.com    1
October14 - October21  abc      mr2@abc.com    1
                       def      mr1@def.com    1
                       xyz      mr1@xyz.com    1
                                mr2@xyz.com    1
Name: Email, dtype: int64

```

For first DataFrame use `sum` per first and second levels and reshape by [`Series.unstack`](http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.unstack.html):

```
df3 = df2.sum(level=[0,1]).unstack(fill_value=0)
print (df3)

Company                abc  def  xyz
date                                
October07 - October14    3    1    1
October14 - October21    1    1    2

```
1. Add a column that maps the date to a week
2. Do something with grouping: i.e. `df.groupby(df.week).count()`