I have a dataframe table (table_1) that contains 3 cloumns:
Iteam ID | Date / time | Date / time |
---|---|---|
12 | 2022-03-21 - 00:27:00 | 2022-03-21 - 00:28:00 |
99 | 2022-03-21 - 00:25:00 | 2022-03-21 - 00:26:00 |
34 | 2022-03-21 - 00:22:00 | 2022-03-21 - 00:23:00 |
28 | 2022-03-21 - 00:21:00 | 2022-03-21 - 00:23:00 |
I want to be able to filter the column Iteam Id with the data in another data-frame column (table_2).
Iteam Id |
---|
12 |
34 |
28 |
So the output would be:
Iteam ID | Date / time | Date / time |
---|---|---|
12 | 2022-03-21 - 00:27:00 | 2022-03-21 - 00:28:00 |
34 | 2022-03-21 - 00:22:00 | 2022-03-21 - 00:23:00 |
28 | 2022-03-21 - 00:21:00 | 2022-03-21 - 00:23:00 |
I have tryed creating a new dataframe using:
new_df = table_1[table_1['Iteam ID'].isin(table_2)
But it is returning an empty dataframe, any help with this would be much appreciated!
CodePudding user response:
You should use the correct column instead of the whole dataframe:
new_df = table_1[table_1['Iteam ID'].isin(table_2['Iteam ID'].values)]
CodePudding user response:
Just merge (inner join) them :
out = df1.merge(df2, on='Iteam Id')