I have a multi-index dataframe and I am trying to count the consecutive winners
The problem is there are some 'NaN' values interspersed within the column values, that I would like to skip when trying to count consecutive winners
week_1 week_2 week_3 week_4 week_5 week_6 \
Year
2000 Arizona Cardinals loser winner loser loser winner loser
Atlanta Falcons winner loser winner loser loser loser
Baltimore Ravens winner NaN winner winner winner winner
Buffalo Bills NaN winner loser loser loser winner
Carolina Panthers loser winner loser loser winner loser
I can use df3 = df.shift(-1, axis =1).isin(['winner'])
to make the comparisons, but this is not going to skip the NaN
values.
So something like this:
Baltimore Ravens winner NaN winner
which should count for as consecutive values will be skipped.
NaN
values. What is your ultimate goal though? Are you counting longest streak for each team and year? – busybear Sep 5 at 23:22