I have df and I want to grab the last line below CUSIP.
In [374]: df.head() Out[374]: CUSIP COLA COLB COLC date 1992-05-08 AAA 238 4256 3.523346 1992-07-13 AAA NaN 4677 3.485577 1992-12-12 BBB 221 5150 3.24 1995-12-12 BBB 254 5150 3.25 1997-12-12 BBB 245 Nan 3.25 1998-12-12 CCC 234 5140 3.24145 1999-12-12 CCC 223 5120 3.65145
I use:
df = df.reset_index().groupby('CUSIP').last().reset_index.set_index('date')
I want it:
CUSIP COLA COLB COLC date 1992-07-13 AAA NaN 4677 3.485577 1997-12-12 BBB 245 Nan 3.25 1999-12-12 CCC 223 5120 3.65145
Instead, I get:
CUSIP COLA COLB COLC date 1992-07-13 AAA 238 4677 3.485577 1997-12-12 BBB 245 5150 3.25 1999-12-12 CCC 223 5120 3.65145
How do I get last () to take the last line of a group, including NaN?
Thanks.
source share