Adler Müller
Adler Müller

Reputation: 248

How to extract date, hours and minutes from datetime

I have a pandas dataframe and I want extract date, hours and minutes to a new column in the following way. I also want to add integer variable at the end of the extracted date/hours/minte:

2017-10-25 10:11:12.002000+00:00

-> int_variable = 7

-> 201710251011 + int_variable

-> 2017102510117

What's the best way doing it?

Upvotes: 0

Views: 908

Answers (1)

jezrael
jezrael

Reputation: 862651

Use Series.dt.strftime with join int_variable by convert to str:

df['date'].dt.strftime('%Y%m%d%H%M') + str(int_variable)

Upvotes: 3

Related Questions