I have 2 dataframes. DF1 is my main dataframe, DF2 is another data set. I need to drop rows from DF1 contain "Security IDs" found in DF2. This new DF will be called DF3. How would I do this?
Sample Dataframe:
df1 = pd.DataFrame({'Security ID': ['10003', '10009', '10010', '10034', '10665'],
'SomeNum': [12,13,13,13,13],
'Color of dogs': ['red','orange','red','red','red'],
'Date1': [20120506, 20120506, 20120506,20120506,20120620],
'Date2': [20120528, 20120507, 20120615,20120629,20120621]})
df2 = pd.DataFrame({'Security ID': ['10003', '10009', '10010', '70011', '70012','70034','70034', '70034'],
'SomeNum': [12,13,13,13,13,13,14,14],
'Num2': [121,122,122,124,125,126,127,128],
'InterestData': [20120506, 20120506, 20120506,20120506,20120620,20120506,20120206,20120405],
'UnreleatedStuff': [20120528, 20120507, 20120615,20120629,20120621,20120629,20120506,20120506]})
Required Resulting Dataframe:
df3 = pd.DataFrame({'Security ID': ['10034', '10665'],
'SomeNum': [13,13],
'Color of dogs': ['red','red'],
'Date1': [20120506,20120620],
'Date2': [20120629,20120621]})
How would I go about this? I tried df3=[~df2.index.isin(df1.index)] after changing the index by df.set_index('Security ID')