ENH: Select what to return when list is empty in explode #35840
Labels
Enhancement
Missing-data
np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Reshaping
Concat, Merge/Join, Stack/Unstack, Explode
Is your feature request related to a problem?
I have used explode function over a df that has sometimes an empty list. The empty list return a
nan
, that raises problems in posteriors processing, because pandas detect them as floats.Describe the solution you'd like
Explode could have a new argument called
return_value_when_empty
or something like that (probably a better and/or shorter name) that allows you to define what to return when a particular row has an empty list. For instance, it could be an empty dict, an empty list, a string, integer or whatever.This way you don't have to use fillna (or more complicated things if fillna doesn't work i.e https://stackoverflow.com/questions/25898888/pandas-replace-all-nan-values-in-dataframe-with-empty-python-dict-objects)
The text was updated successfully, but these errors were encountered: