Search code examples
pythondataframedictionaryanomaly-detection

How to filter dictionary of dataframes by size?


I have dictionary of dataframes which contains over 2000 different dataframes. Key is index(combination of 3 columns-like plant,material,workcenter) value is the data which contains different measurements.

I want to work on outlier detection but some dataframes in that dictionary has 1 or 2 records. So I want to eliminate these dataframes from the dictionary. I searched but there are very few info about how to do that. Can you help?

Maybe I approach in wrong direction, what do you suggest instead?

Thanks in advance


Solution

  • How about, if d is your dictionary:

    filtered_dict = {k: v for (k, v) in d.items() if len(v) > 100}  # Or any number you'd like to filter by