You got a good answer already, but I think it will be useful to show how to think about error messages properly.
Let’s think about the problem logically.
Do we understand what “concatenate” means? If not, we can look that up. We find that it means: to take two strings (pieces of text), and figure out the string that we get by putting them one after the other.
The next step is to apply logic. The error says that we can only use a str
to concatenate to a str
, and that we can’t use a Timedelta
(i.e., a time-delta) to concatenate to a str
(i.e., a string). Therefore, what is the problem? It must be, that the code says to concatenate a time-delta to a string, and this is a problem because it does not make sense to try that.
Where does the code say that? In the place that the error message tells us. Experienced programmers can see the problem anyway, but for your own reference you should look at the entire error message, which will tell you this. It will point to the line window = wc_slab[time:min(time + pd.Timedelta(minutes=10), len(wc_slab))]
; and in newer versions it should highlight (by using ^
symbols underneath) the time + pd.TimeDelta(minutes=10)
part.
Next step: did we want to concatenate to a string? I am guessing no. I am guessing that you expected to have a time and a time-delta; and that you wanted to use +
as arithmetic, to find the new time.
Therefore, what is wrong? We expected to have a time and a time-delta, and the error message tells us that we have a string and a time-delta. Therefore, the problem is that we have a string where we should have a time instead.
Why do we have a string instead of a time? We answer this by checking to find out where the value came from. Here, the code says for time in shot_times:
, so that’s where the time
value came from. It seems like shot_times
was expected to contain times, but it contains strings instead.
Should shot_times
contain strings? Only you can answer this, because it is your code and you are the one who planned out the design.
If shot_times
should contain times instead, then we need to fix the code that set it up in the first place. Otherwise, we need to fix the code here, so that we can take the string that was given to us, and get a time instead.
Given a string, how do we get a time? You show how the time “is notated” - this makes it sound like you knew that you had a string all along, and really just want to know how to do the conversion. In this case, it would be better to ask about that directly - both when posting on a forum, and when trying to use a search engine to get help. Most of the time, debugging an error is much harder than researching a how-to question.
That said, there are many ways to do this. Since it appears that you are already using Pandas, the natural way is to create a pd.Timestamp
from the string, the way that @abessman shows. That is a type provided by Pandas that describes a time, to which a Pandas time-delta can be added.