小编use*_*621的帖子

按列分组以查找另一列中最频繁的值?

按列分组以在另一列中查找最频繁的值。例子:

import pandas as pd
d = {'col1': ['green','green','green','blue','blue','blue'],'col2': ['gx','gx','ow','nb','nb','mj']}
df = pd.DataFrame(data=d)
df
Run Code Online (Sandbox Code Playgroud)

给出:

col1   col2
green  gx
green  gx
green  ow
blue   nb
blue   nb
blue   xv
Run Code Online (Sandbox Code Playgroud)

结果:

因为green拥有gxblue拥有nb

python group-by pandas pandas-groupby

6
推荐指数
1
解决办法
5591
查看次数

标签 统计

group-by ×1

pandas ×1

pandas-groupby ×1

python ×1