0

Im a little confused about how to incorporate if, then statements into dataframes. DF:

name date1 date2
A 2018-08-24 2019-09-24
A 2018-08-25 2018-08-24
A 2017-08-25 2018-08-24
A 2016-08-25 2018-08-24
B 2018-08-25 2019-09-24
C 2018-08-25 2019-09-24
C 2015-04-25 2019-09-24
C 2018-06-25 2019-09-24
C 2008-06-25 2019-09-24
D 2018-06-25 2019-09-24
D 2008-06-25 2019-09-24

I want to first compare the values in column, 'name'. If these values are the same, I want to proceed with a calculation for the other two columns. For example, the first two rows have the same string in 'name', so I want to proceed evaluating if date2-date1 overlaps between the first row and second row.
What is the best way to approach this?

suzieblue
  • 41
  • 4
  • 1
    Are there multiple rows with duplicate names? i.e. Are there at most only two rows with name `A` or is it possible for three or more rows to have name `A`? – Daniel Apr 04 '21 at 01:12
  • you mean 2 adjacent rows at a time? or all combinations of rows? or all "groups" of names? – tdy Apr 04 '21 at 01:12
  • It sounds like you probably want to use a groupby on the `name` column, but some more details would be helpful so that people on StackOverflow can more accurately answer your question. Can you give a more extensive example with the expected output DataFrame? – Derek O Apr 04 '21 at 01:22
  • Yes there can be more than 2 rows with duplicate names. I have edited the example accordingly. – suzieblue Apr 04 '21 at 01:55
  • 1
    I think this is the same question as https://stackoverflow.com/questions/42462218/find-date-range-overlap-in-python – John Zwinck Apr 04 '21 at 03:07
  • What's your expected output? – Ynjxsjmh Apr 04 '21 at 04:16

0 Answers0