The basic mathematical operators work on DataFrames. For example, a new column can be obtained as a result of adding, multiplying, subtracting, or dividing two columns:
In [67]: ore1DF["add_iron_copper"] = ore1DF["iron"] + ore1DF["copper"]
The following is the output:
Logical operators such as | (or), & (and), and ^ (not) work on DataFrames. Consider the following two DataFrames:
logical_df1 = pd.DataFrame({'Col1' : [1, 0, 1], 'Col2' : [0, 1, 1] }, dtype=bool)
logical_df2 = pd.DataFrame({'Col1' : [1, 0, 0], 'Col2' : [0, 0, 1] }, dtype=bool)
Now, performing the logical or between these two columns yields the following result:
logical_df1 | logical_df2
The following is the output:
Operations can also be performed on DataFrames using the NumPy functions:
np.sqrt(ore1DF)
The following is the output: