python - Pandas dataframe filiter out groups of small sizes -



python - Pandas dataframe filiter out groups of small sizes -

i'm trying filter out groups of little sizes , filter function throws valueerror: negative dimensions not allowed. caan't post code it's specific , can't reproduce issue random set of data. have come across this? i've seen other post same error wasn't helpful

as work-around i'm trying same thing filter groupby , apply doesn't work expected. suggestions?

dff = pd.dataframe({'a': np.arange(8), 'b': list('aabbbbcc')}) dff['c'] = np.arange(8) def f(x): if len(x)>2: homecoming x else: homecoming none dff.groupby('b').apply(f) b b c 2 nan nan nan 3 nan nan ... b b c 2 2 b 2 3 3 b 3 4 4 b 4 5 ... c b c 2 nan nan nan 3 nan nan ... dtype: object

the problem illustration code apply doesn't know none when putting dataframe together. apply function needs output same type of object every time. if homecoming pd.dataframe() instead of none should you're looking for.

python pandas

Comments

Popular posts from this blog

php - How to pass multiple values from url -

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

database - php search bar when I press submit with nothing in the search bar it shows all the data -