[英]How to aggregate all values in a pandas dataframe columns in 2 values
I have a Pandas dataframe contains some columns.我有一个 Pandas 数据框包含一些列。 Each columns have some differents values.
每列都有一些不同的值。 See the image.
看图片。
In col1 I have that the value 1 is more frequent than others, so, I need to transform this column to have values 1 and more then 1.在 col1 中,值 1 比其他值更频繁,因此,我需要将此列转换为值 1 和大于 1。
How can I do that?我怎样才能做到这一点?
My goals here is transforme this column in a categorical column but I have no idea how can I do that.我的目标是将此列转换为分类列,但我不知道该怎么做。
The output expected is something like the next image:预期的输出类似于下一张图片:
Try clip function on column:在列上尝试剪辑功能:
df["col1"].clip(upper=2)
0 1
1 2
2 2
3 2
4 1
5 2
6 2
7 1
8 1
9 1
10 1
11 2
12 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.