Issue
So I need to filter out rows from one data frame using another dataframe as a condition for it.
df1:
system code
AIII-01 423
CIII-04 123
LV-02 142
df2:
StatusMessage Event
123 Gearbox warm up
So for this example I need to remove the rows that has the code 423 and 142.
How do I do that?
Solution
Plug and play script for you. If this doesn't work on your regular code, check to make sure you have the same types in the same columns.
import pandas as pd
df1 = pd.DataFrame(
{"system": ["AIII", "CIII", "LV"], "Code": [423, 123, 142]}
)
df2 = pd.DataFrame(
{"StatusMessage": [123], "Event": ["Gearbox warm up"]}
)
### This is what you need
df1 = df1[df1.Code.isin(df2.StatusMessage.unique())]
print(df1)
Answered By - zerecees
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.