How to add a new time column with new calculated time data?
mrbiggleswirth opened this issue · 2 comments
mrbiggleswirth commented
Hi Just Markham,
I want to add +8 hours to all the existing times and save it to a new column in the DataFrame. I only figured out how to create a new column. But I don't know how to add my delta time to the new time data.
Electronically yours,
Mr. Biggles
from datetime import timedelta
import pandas as pd
ufo = pd.read_csv('http://bit.ly/uforeports')
print("")
ufo['Time'] = pd.to_datetime(ufo.Time)
print(ufo)
print("")
print("_______________________________________________________________________")
print("")
print("ufo.dtypes")
print(ufo.dtypes)
print("")
print("_______________________________________________________________________")
print("")
# Add a new column with new data.
delta = timedelta(hours=-8)
# calc_utc_time = data_cell + delta
ufo['utc_time'] = ufo.Time
print(ufo)
print("")
print("_______________________________________________________________________")
print("")
print("ufo.dtypes")
print(ufo.dtypes)
print("")
print("_______________________________________________________________________")
print("")
mrbiggleswirth commented
I solved it! :) The required Kung Fu can be found in these lessons:
Lesson: 25 How do I work with dates and times in pandas? (10:20)
Lesson: 8 How do I filter rows of a pandas DataFrame by column value? (13:44)
Thank you, Shifu Markham!
justmarkham commented
@mrbiggleswirth Great to hear it! 🙌