Addition/subtraction of integers and integer-arrays with Timestamp is no longer supported. Instead of adding/subtracting `n`, use `n * obj.freq`

Bushra Akram picture Bushra Akram · Apr 11, 2020 · Viewed 13.3k times · Source

I am using pytrends library to extract google trends and i am getting the following error:

Addition/subtraction of integers and integer-arrays with Timestamp is no longer supported. Instead of adding/subtracting n, use n * obj.freq

timeframes = []
datelist = pd.date_range('2004-01-01', '2018-01-01', freq="AS")
date = datelist[0]
while date <= datelist[len(datelist)-1]:
    start_date = date.strftime("%Y-%m-%d")
    end_date = (date+4).strftime("%Y-%m-%d")
    timeframes.append(start_date+' '+end_date)
    date = date+3

Answer

azro picture azro · Apr 11, 2020

You may not sum a date and a number like date+4 because who knows which unit this is, 4h, 4d, 4m, ... ?

You may use datetime.timedelta, here's an example if you meant days

from datetime import timedelta

end_date = (date+timedelta(days=4)).strftime("%Y-%m-%d")
# ...
date = date+timedelta(days=3)