我使用了包含许多列的汽车数据框。如果我得到某些制造商的出现次数:
carsDF.manufacturer.value_counts()
结果类似于:
VW 2228
Opel 1414
Renault 1362
Audi 895
BMW 888
Mercedes-Benz 786
如果某个制造商的出现总数小于特定数量,如何从数据框中删除该制造商的所有行?
最佳答案
你可以做一个 map :
# get the count for each manufacturer
counts = carsDF.manufacturer.value_counts()
# threshold
thresh = 1000
# replace the manufacturer with the counts and thresholding
carsDF[carsDF.manufacturer.map(counts).ge(thresh)]
关于python - 根据分类列中不同值的计数从 pandas 数据框中删除所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58314135/