2021年4月3日星期六

Pandas dataframe - comparing values in other columns only for rows with matching labels in one column

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 | | B | 2018-08-25 | 2019-09-24 | | C | 2018-08-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?

https://stackoverflow.com/questions/66937183/pandas-dataframe-comparing-values-in-other-columns-only-for-rows-with-matching April 04, 2021 at 09:06AM

没有评论:

发表评论