Skip to content
Advertisement

How to add hours to the original time in dataframe then generate a new date?

The data in test.csv likes this:

JavaScript

I want to remove the +00:00 in upload_time and add 8 hours to upload_time ,then generate a new column new_upload_time.

I use this code to do it.

JavaScript

result.csv:

JavaScript

Although I have implemented it, I feel that the code is a bit complicated.

Is there a simple way?

Advertisement

Answer

Do the formatting after adding 8 hours. You are formatting as a string and then trying to add a number to it. Add the number first and then format as string with strftime:

JavaScript

You can also specify the date_format on export:

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