[英]df.loc and value count
So I am trying to get the first letter of a column and then get the value counts for that letter所以我试图获取列的第一个字母,然后获取该字母的值计数
df5 = pd.DataFrame(df['EmployeeLastName'].astype(str).str[0].value_counts())
and then select only the values that are more than 50然后只选择大于 50 的值
df5.loc[df5['EmployeeLastName'] > 50]
Is there a way I can accomplish this without creating a new data frame?有没有一种方法可以在不创建新数据框的情况下完成此操作?
I tried this put it is resulting in an error.我试过这把它导致了一个错误。
df.loc[ df['EmployeeLastName'].astype(str).str[0].value_counts() > 50 ]
Thanks谢谢
Use groupby
and transform
使用groupby
和transform
df.loc[(df.groupby(df['EmployeeLastName'].str[0])
.transform('count') > 50).squeeze()]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.