Searching for keywords in dataframe
import pandas as pd

df = pd.read_clipboard(sep=',') # copied data from the gist

branches_of_sci = ['bio', 'chem', 'physics']

for branch in branches_of_sci:
    df[branch] = df.astype(str).sum(axis=1).str.contains(branch)


In my limited experience, for loops are almost always wrong when using Pandas.  The primary benefit of Pandas is vectorization, so using the built-in methods is typically best.

Here is a breakdown of the main function:


df[branch]  creates a new dataframe column
df.astype(str) converts all of the dtypes in the dataframe to strings
.sum(axis=1) concatenates all dataframe columns horizontally (i.e. axis=1)
.str.contains() use built-in string search (see docs)


Hopefully that helps.