Using df.merge with an inner join

This is the second option. Let's now use the df.merge() method from the pandas library. The idea is simple. First of all, we concatenate the individual dataframes from each of the subjects, and then we use df.merge() methods.

Check the following code:

dfSE = pd.concat([df1SE, df2SE], ignore_index=True)
dfML = pd.concat([df1ML, df2ML], ignore_index=True)

df = dfSE.merge(dfML, how='inner')
df

Here, you performed an inner join on each dataframe. That is to say, if an item exists in both dataframes, it will be included in the new dataframe. This means we will get a list of students who appeared in both the courses. 

The output of the preceding code is shown in the following screenshot:

Note that this should answer one of the questions mentioned earlier: we now know there are 21 students who took both the courses. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.135.175