Skip to content
Advertisement

Add hours to datetime of rows in a specific time interval

Let it be the following Python Panda DataFrame:

JavaScript

Given a date and time range (start and end) and a country_ID, I want to add 2 hours to the rows that are in that range:

Example:

JavaScript
JavaScript

Advertisement

Answer

Try your logic with boolean indexing (date must also be a datetime object, not a string):

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement