[英]Same lengtht for a group of values in a column of a Data Frame
I would like to get the same lengtht for a group of values (0,1,2,3,4,5) in a column of a Data Frame.我想为数据框的列中的一组值(0、1、2、3、4、5)获得相同的长度。 For example, I would like to reduce the amount of every group of values to the lowest exisiting (= 41)
例如,我想将每组值的数量减少到现有的最低值(= 41)
input: train_df.relevancy.value_counts()
输入:
train_df.relevancy.value_counts()
output: output:
IIUC use GroupBy.head
by minimal value from Series.value_counts
: IIUC 通过
GroupBy.head
的最小值使用Series.value_counts
:
val = train_df.relevancy.value_counts().min()
train_df = train_df.groupby('relevancy').head(val)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.