I tried using itertools.groupby
with a pandas Series. But I got:
TypeError: boolean value of NA is ambiguous
Indeed some of my values are NA
.
This is a minimal reproducible example:
import pandas as pd
import itertools
g = itertools.groupby([pd.NA,0])
next(g)
next(g)
Comparing a NA
always results in NA
, so g.__next__
does while NA
and fails.
Is there a way to solve this, so itertools.groupby
works with NA
values? Or should I just accept it and use a different route to my (whatever) goal?