尤汉·罗斯
我目前有以下标签分布
Lbl
0 10451
1 1481
dtype: int64
如何平衡标签?例如只选择1481的0?
给定数据框
index | 1 | 2 | 3 | ... | Lbl
谢谢
编辑:添加图片以解决答案中讨论的问题:
我得到上面的^^代码
print(table_train[:5])
table_train = table_train.groupby('Lbl').apply(lambda x : x.sample(1481)).reset_index(level=1, drop=True)
print(table_train[:5])
BEN_YO
您可以在sample
之后尝试groupby
df.groupby('Label').apply(lambda x : x.sample(1481)).reset_index(level=0,drop=True)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
编辑于
我来说两句