I have several daily yields and I have grouped them into months using the following code:
df2['trd_exctn_dt'] = pd.to_datetime(df2['trd_exctn_dt'])
group_ym = df2.groupby(df2['trd_exctn_dt'].dt.strftime('%Y-%m'))
I now want to find the middle row within each of these groups, however how would I do this as each group has a different number of rows in, therefore I cannot use a specific number to find the middle row
For example:
| cusip_id | yld_pt | trd_exctn_dt | trd_exctn_tm |
|---|---|---|---|
| 00077TB0 | 6.58902 | 2015-01-05 | 578906.09 |
| 00077TB0 | 6.43672 | 2015-01-06 | 523452.12 |
| 00077TB0 | 6.45628 | 2015-01-07 | 555532.10 |
| 00077TB0 | 6.23452 | 2015-02-10 | 567392.02 |
| 00077TB0 | 6.34552 | 2015-03-12 | 545930.98 |
My desired answer would be:
| cusip_id | yld_pt | trd_exctn_dt | trd_exctn_tm |
|---|---|---|---|
| 00077TB0 | 6.43672 | 2015-01-06 | 523452.12 |
| 00077TB0 | 6.23452 | 2015-02-10 | 567392.02 |
| 00077TB0 | 6.34552 | 2015-03-12 | 545930.98 |