Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create a list or array of date time using pandas

I am trying to create a list of date time in python using pandas. I want something like:

2023-05-10_00:00:00
2023-05-10_01:00:00
2023-05-10_02:00:00
.....
.....
2023-05-10_23:00:00

So basically I want data with datetime with 1 hour increment. I tried the following

dt = pd.to_datetime('2023-05-10',format='%Y-%m-%d')
print(dt)

which gives me the following, and it is not exactly what I am looking for

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

2023-05-10 00:00:00

I was also thinking of creating a list or array with just the date 2023-05-10 and another array with only time with 1-hr increment, and then paste them together with a separator _. I am not sure how to do this in Python.

Thanks in advance.

>Solution :

i make 3 data for example

pd.date_range('2023-05-10', periods=3, freq='H').strftime('%Y-%m-%d_%H:%M:%S')

output:

Index(['2023-05-10_00:00:00', '2023-05-10_01:00:00', '2023-05-10_02:00:00'], dtype='object')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading