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 new dataframe based on a list of strings and a interval of dates

I need to create a new dataframe that is the result of generating for each of the values ​​of dataframe 2, a time interval per hour. In such a way that dataframe 1 is only a date range and that range has to be repeated for each of the values ​​of the other dataframe.

The value of the hours will always be sorted since it has a start date and end date range.

Input Dataframe 1:

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

Date Hour
2021-05-15 1
2021-05-15 2
2021-05-15 3
2021-05-15 4

Input Dataframe 2:

Class
A
B
C

Expected Output:

Date Hour Class
2021-05-15 1 A
2021-05-15 2 A
2021-05-15 3 A
2021-05-15 4 A
2021-05-15 1 B
2021-05-15 2 B
2021-05-15 3 B
2021-05-15 4 B
2021-05-15 1 C
2021-05-15 2 C
2021-05-15 3 C
2021-05-15 4 C

Thank!!

>Solution :

Try this:

new_df = pd.merge(df,df2,how = 'cross')
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