0
I have a dataframe that has an index of date type and contains hourly data per day.

I need to take only the rows which have the last record of the day 
and filter out REST OF THE RECORDS FOR THAT DAY ONLY... 

and do the same for other days.
                   COL-A
DATE    
2014-01-01 00:56:00     NaN
2014-01-01 01:56:00     NaN
2014-01-01 02:56:00     NaN
2014-01-01 03:56:00     NaN
2014-01-01 04:00:00     NaN
2014-01-01 04:56:00     42.0
2014-01-01 05:56:00     NaN
2014-01-01 06:56:00     NaN
2014-01-01 07:56:00     NaN
2014-01-01 08:56:00     NaN
2014-01-01 09:56:00     NaN
2014-01-01 10:00:00     19.0
2014-01-01 10:56:00     NaN
2014-01-01 11:56:00     NaN
2014-01-01 12:56:00     NaN
2014-01-01 13:56:00     NaN
2014-01-01 14:56:00     NaN
2014-01-01 15:56:00     NaN
2014-01-01 16:00:00     NaN
2014-01-01 16:56:00     36.0
2014-01-01 17:56:00     NaN
2014-01-01 18:56:00     NaN
2014-01-01 19:56:00     NaN
2014-01-01 20:56:00     NaN
2014-01-01 21:56:00     NaN
2014-01-01 22:00:00     NaN
2014-01-01 22:56:00     NaN
2014-01-01 23:56:00     NaN
2014-01-01 23:59:00     41.0
2014-01-02 00:56:00     NaN
...
...
...

I need to keep only the row 2014-01-01 23:59:00 41.0

1
  • or just df.resample('D').last() Commented Aug 25, 2019 at 5:00

1 Answer 1

1

Try this.

df.groupby([pd.Grouper(key = 'DATE', freq = 'd')]).last()
Sign up to request clarification or add additional context in comments.

2 Comments

it threw up 'Grouper named DATE is not found' so i removed key='DATE' and kept only df.groupby([pd.Grouper(freq = 'd')]).last() ... looks like it works.. will it give unexpected result?
Since the DATE is already index. it should not give any unexpected results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.