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
CodePudding user response:
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