Pandas Series: maximum recursion error when replacing empty lists · Issue #21977 · pandas-dev/pandas (original) (raw)
I have a pandas Series containing lists. I wanted to replace empty lists with NaN. My first approach was using .replace, but that unexpectedly gave me a maximum recursion error.
I am using pandas 0.21.1 on Python 3.4, but other users had the same problem on 0.23
import numpy as np
import pandas as
ts = pd.Series([[1], [2, 3], [], [4]])
ts.replace([], np.nan)
RuntimeError: maximum recursion depth exceeded in comparison
I achieved the desired output using:
ts[ts.apply(len) == 0] = np.nan
but I don't understand the maximum recursion error