Suppose we have a code in form of string and we want to run it replacing values of variables. It can be achieved via eval function.
So this recipe is a short example on how to aggregate using group by in pandas over multiple columns. Let's get started.
import pandas as pd import seaborn as sb
Let's pause and look at these imports. Pandas is generally used for performing mathematical operation and preferably over arrays. Seaborn is just used in here to import dataset.
df = sb.load_dataset('tips') print(df.head())
Here we have imported tips dataset from seaborn library.
Here we are groupby on certain columns and finally taking the sum of each identity of columns.
Once we run the above code snippet, we will see:
Scroll down to the ipython file to look at the results.
We can see the data being aggregated on specified columns.