Home > Software design >  Pandas add a static date to a series
Pandas add a static date to a series

Time:03-16

I don't know how to add a static date to a a time series:

The serie in string look like this:

time_s=pd.Series(['000329','000458','154259','232810'])

I convert it in time serie:

time_s=pd.to_datetime(time_s,format='%H%M%S')

But the date is contained in the name of the file :

date_file=datetime.datetime(year=year, month=month, day=day)

The simple "way" doesn't work:

date_file time_s

I tried to create a series with the static date and add both:

serie_date=[pd.to_datetime(date_file) for x in range(len(time_s)) ]
pd.Series(serie_date) time_s

Someone can help me please? Thx

CodePudding user response:

You can join strings from datetime first and then generate datetimes:

out = pd.to_datetime(date_file.strftime('%Y-%m-%d')   time_s,format='%Y-%m-%d%H%M%S')
  • Related