需求:过滤掉pandas DataFrame中出现次数较少的行,可以采用下面的写法:df为待过滤数据
df_family_car = df.groupby("PLATE_INFO_EX").filter(lambda x: (len(x) > 500 and len(x)<1000))
详细研究groupby用法,参考链接:https://blog.csdn.net/songbinxu/article/details/79839363
https://blog.csdn.net/youngbit007/article/details/54288603/
新建数据:
import pandas as pd
df = pd.DataFrame({'key1':list('aabba'),
'key2': ['one','two','one','two','one'],
'data1': np.random.randn(5),
'data2': np.random.randn(5)})
df
Out[83]:
key1 key2 data1 data2
0 a one -0.643930