I have code that loops through a column of a dataframe. How can I make this code faster? (Python/Pandas)
Is this what you want?
import pandas as pd

datasetA = pd.DataFrame(
    [
        [
            'ID222'
        ],
        [
            'ID233'
        ],
        [
            'ID2123'
        ],
        [
            'ID233'
        ]
    ], columns = ['ID']
)

datasetB = pd.DataFrame(
    [
        [
            'ID222'
        ],
        [
            'ID233'
        ],
        [
            'ID212355'
        ],
        [
            'ID233'
        ]
    ], columns = ['ID']
)
datasetA[&quot;inB&quot;] = datasetA.ID.isin(datasetB.ID)
datasetA.drop_duplicates()

    ID  inB
0   ID222   True
1   ID233   True
2   ID2123  False