I have these lines of code;
for name in clean.alpha_names:
CategoryGroupLists=df_new_housing.groupby(name)['SALE PRICE'].apply(list)
When I run the code, the CategoryGroupLists contains content that looks like this;
I want to remove the empty list entries for FIELDSTON and FINANCIAL. I think I need something like a HAVING clause next to my GROUPBY, although PANDAS does not have a HAVING clause. So how do I do this?
EDIT: One suggestion is that I use a filter. However with the following code I get an error;
for name in clean.alpha_names:
CategoryGroupLists=df_new_housing.groupby(name)['SALE PRICE'].filter(lambda x: len(x) > 1).apply(list)
TypeError: 'int' object is not iterable
EDIT2 My workaround for now is to use the following code. However I am sure there is a better way of doing it. Follow the original assignment with;
# Remove empty lists from the CategoryGroupLists
for idx in (CategoryGroupLists.index):
if len(CategoryGroupLists[idx]) == 0:
del CategoryGroupLists[idx]