I have the following code:
import pandas as pd
A = [1, 2, 2, 6, 5]
B = [4, 5, 5, 5, 4]
C = ['-'] * len(A)
d = {'A': A, 'B': B, 'C': C}
df = pd.DataFrame(data=d)
df.loc[df['A'] >= 3, 'C'] = 'A>=3'
df.loc[df['B'] >= 3, 'C'] = 'B>=3'
print(df)
How to append a string to the C column instead of writing a new value?
The current result:
A B C
0 1 4 B>=3
1 2 5 B>=3
2 2 5 B>=3
3 6 5 B>=3
4 5 4 B>=3
The desired result:
A B C
0 1 4 B>=3
1 2 5 B>=3
2 2 5 B>=3
3 6 5 A>=3 B>=3
4 5 4 A>=3 B>=3