I have a dataframe as below:
Name Age
0 Alex 10
1 Bob 12
2 Clarke 13
The dataframe is created as:
data = [['Alex',10],['Bob',12],['Clarke',13]]
df = pd.DataFrame(data,columns=['Name','Age'])
I want to perform string concatenation of the two columns as:
Name Age
0 10 Alex 10
1 12 Bob 12
2 13 Clarke 13
I tried using df["Name"] = df["Age"]+" "+df["Name"]
, which resulted in the below error:
Traceback (most recent call last): File "", line 1, in File "/anaconda3/envs/env1/lib/python3.6/site-packages/pandas/core/ops/common.py", line 65, in new_method return method(self, other) File "/anaconda3/envs/env1/lib/python3.6/site-packages/pandas/core/ops/init.py", line 343, in wrapper result = arithmetic_op(lvalues, rvalues, op) File "/anaconda3/envs/env1/lib/python3.6/site-packages/pandas/core/ops/array_ops.py", line 189, in arithmetic_op res_values = na_arithmetic_op(lvalues, rvalues, op) File "/anaconda3/envs/env1/lib/python3.6/site-packages/pandas/core/ops/array_ops.py", line 149, in na_arithmetic_op result = masked_arith_op(left, right, op) File "/anaconda3/envs/env1/lib/python3.6/site-packages/pandas/core/ops/array_ops.py", line 111, in masked_arith_op result[mask] = op(xrav[mask], y) numpy.core._exceptions.UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U21'), dtype('<U21')) -> dtype('<U21')