I am working on a project and so far my code looks like this:
def vacation_date(row):
if pd.isnull(row['vacation_date']) == False :
return float((row['vacation_date'] - row['purchased_trip_date']).days)
else:
pass
preprocessed_data['vacation_date'] = data.apply(lambda row:
vacation_date(row), axis=1)
it is returning: TypeError: ("unsupported operand type(s) for -: 'Timestamp' and 'str'", 'occurred at index 3')
I am not sure what I need to do to fix this, any suggestions are appreciated, thanks!
The error message is one of the clearest I've ever seen in computing - it's telling you that you're trying to subtract a string from a Timestamp. Since what you're subtracting is row['purchased_trip_date']
, it means this is a string. Convert it to another Timestamp
first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With