I have one dataframe with 9 columns as below:
C0 C1 C2 C3 C4 C5 C6 C7 C8
1 1 1 0 0 1 0 0 0
1 1 1 0 4 0 0 2 3
1 1 1 0 0 2 4 1 3
0 2 0 0 1 0 0 0 0
0 2 0 2 0 0 4 1 3
0 2 0 2 4 0 4 1 3
0 2 0 2 4 0 4 1 3
0 2 0 0 4 0 4 1 3
I would like to return mode value of each column. I know that it can be done by using mode() in Python. However, I would like to add the condition that if there are >= 3 number "1" in the column, return mode=1 instead of the real mode of the column. And if there are >=4 number "2", return mode=2 instead of the real mode of the column. Else, return the real mode values.
The output of the code should be:
C0 C1 C2 C3 C4 C5 C6 C7 C8
1 2 1 0 4 0 4 1 3
Please help me. Thank you.