How to combine two columns into one in a DataFrama

Viewed 23

I have a DataFrame with two columns and want to combine their contents into another column. In the 3rd column, I will like to replace all entries that are 'hello' by the corresponding non 'hello' term. But my just returns df['C'] as the string addition of the df['A'] and df['B'].

df = pd.DataFrame({'A' : ['here', 'there', 'hello', 'hello', 'hello'],
                        'B' : ['hello', 'hello', 'go', 'click', 'clack']})
df['C'] = df['A'] + df['B']

I will be glad if someone can help me.

0 Answers
Related