pythonpandasgoogle-trends

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


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

Solution

  • You can't sum a date and a number like date+4 because who knows which unit this is, 4h, 4d,... ?


    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)