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

looking to filter on dataframe based on another

First Df contains dates and attendance with names

date            1        2     3   .....50
2021-10-01    jhohn     bob    jerry.....
2021-10-02    Ram       jhohn  bob    jerry
Second df contains
date        name  activity_info(multiple columns)
2021-10-01  john  fgfhfgh
2021-10-01  Ram   dfsdfsdf

I want to filter out data for the elements not present in first Data frame on that particular date.
for instance Ram is not in 2021-10-01. that has to be removed. the number of columns may vary

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

>Solution :

You can melt first data and inner join with second data:

df1.melt('date', value_name='name').merge(df2, on=['date','name'])

Output:

         date variable   name activity_info
0  2021-10-01        1  jhohn       fgfhfgh
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