Skip to content
Advertisement

Conditional lambda in pandas returns ValueError

In a df comprised of the columns asset_id, event_start_date, event_end_date, I wish to add a forth column datediff that for each asset_id will capture how many days passed between a end_date and the following start_date for the same asset_id, but in case that following start_date is earlier than the current end_date, I would like to capture the difference between the two start_dates. Dataset is sorted by (asset_id, start_date asc).

In Excel it would look something like:

enter image description here

I tried:

JavaScript

But this is:

  1. not working. Throwing ValueError: The truth value of a Series is ambiguous.
  2. so un-elegant.

Thanks!

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement