I have this dataframe:
df = pd.DataFrame({"X" : ["2017-12-17","2017-12-18","2017-12-19"],
"Y": ["F","W","Q"]})
And I'm looking for the key
column:
X Y key
0 2017-12-17 F 2017-12-17_F
1 2017-12-18 W 2017-12-18_W
2 2017-12-19 Q 2017-12-19_Q
I have tried 1,2,3, and the best solution is (for speed, as they are near 1 million rows):
df.assign(key=[str(x) + "_" + y for x, y in zip(df["X"], df["Y"])])
And it gives me this error:
TypeError: unsupported operand type(s) for +: 'Timestamp' and 'str'
Why?