I have a dataframe like below:
| name | date | col1 | col2 |
|---|---|---|---|
| A | 2021-03-01 | 0 | 1 |
| A | 2021-03-02 | 0 | 0 |
| A | 2021-03-03 | 3 | 1 |
| A | 2021-03-04 | 1 | 0 |
| A | 2021-03-05 | 3 | 1 |
| A | 2021-03-06 | 1 | 0 |
| B | 2021-03-01 | 1 | 0 |
| B | 2021-03-02 | 2 | 0 |
| B | 2021-03-03 | 3 | 1 |
| B | 2021-03-04 | 0 | 1 |
| B | 2021-03-05 | 0 | 0 |
| B | 2021-03-06 | 0 | 0 |
I'd like to group by the names and find the number of days spanned by the nonzero entries of the other non-date columns (basically excluding any leading or trailing zeroes) to get something like:
| name | col1 | col2 |
|---|---|---|
| A | 4 | 5 |
| B | 3 | 2 |
How can I do this without resorting to a for loop?