0

Have df with values.


name     last_date                     submission_date

mike  2020-04-10 02:22:22.222   2020-04-01 02:22:22.222
mike  2020-04-10 02:22:22.222   2020-04-08 02:22:22.222
mike  2020-04-10 02:22:22.222   2020-04-16 02:22:22.222

ross  2020-04-16 02:22:22.222   2020-04-18 02:22:22.222
ross  2020-04-16 02:22:22.222   2020-04-19 02:22:22.222
ross  2020-04-16 02:22:22.222   2020-04-20 02:22:22.222
ross  2020-04-16 02:22:22.222   2020-04-15 02:22:22.222

carter 2020-04-22 02:22:22.222   2020-04-28 02:22:22.222
carter 2020-04-22 02:22:22.222   2020-04-15 02:22:22.222
carter 2020-04-22 02:22:22.222   2020-04-19 02:22:22.222
carter 2020-04-22 02:22:22.222   2020-04-21 02:22:22.222



filter values based on last_date. exclude values of submission_date if it is greater than last_date

expected output:

name     last_date                     submission_date

mike  2020-04-10 02:22:22.222   2020-04-01 02:22:22.222
mike  2020-04-10 02:22:22.222   2020-04-08 02:22:22.222

ross  2020-04-16 02:22:22.222   2020-04-15 02:22:22.222

carter 2020-04-22 02:22:22.222   2020-04-15 02:22:22.222
carter 2020-04-22 02:22:22.222   2020-04-19 02:22:22.222
carter 2020-04-22 02:22:22.222   2020-04-21 02:22:22.222




3
  • you can just query: df.query("last_date>=submission_date") ? Commented Apr 18, 2020 at 13:29
  • What have you tried so far ? Where are you stuck? Commented Apr 18, 2020 at 13:30
  • @anky i need to exclude values of submission_date Commented Apr 18, 2020 at 13:31

1 Answer 1

1

You can query the dataframe where submission_date is less than or equal to last_date , this returns the rows where the condition is met an filters out the rest:

df.query("last_date>=submission_date")

    name                 last_date         submission_date
0   mike   2020-04-10 02:22:22.222 2020-04-01 02:22:22.222
1   mike   2020-04-10 02:22:22.222 2020-04-08 02:22:22.222
2   ross   2020-04-16 02:22:22.222 2020-04-15 02:22:22.222
3  carter  2020-04-22 02:22:22.222 2020-04-15 02:22:22.222
4  carter  2020-04-22 02:22:22.222 2020-04-19 02:22:22.222
5  carter  2020-04-22 02:22:22.222 2020-04-21 02:22:22.222
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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