I have two dataframes, which both have an Order ID
and a date
.
I wanted to add a flag into the first dataframe df1
: if a reco
The problem is that you can't add an object array (containing strings) to a number array, that's just ambiguous:
>>> import pandas as pd
>>> pd.Series(['abc', 'def']) + pd.Series([1, 2])
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U21') dtype('<U21') dtype('<U21')
You need to explicitly convert your Dates
to str
.
I don't know how to do that efficiently in pandas but you can use:
df1['key'] = df1['Order_ID'] + '_' + df1['Date'].apply(str) # .apply(str) is new