<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Groupby operations
Some imports
Step1:  Some 'theory'
Step2:  Using the filtering and reductions operations we have seen in the previous notebooks, we could do something like
Step3:  And many more methods are available. 
And now applying this on some real data
We go back to the titanic survival data
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
try:
    import seaborn
except ImportError:
    pass
pd.options.display.max_rows = 10
Explanation: Groupby operations
Some imports:
End of explanation
df = pd.DataFrame({'key':['A','B','C','A','B','C','A','B','C'],
                   'data': [0, 5, 10, 5, 10, 15, 10, 15, 20]})
df
Explanation: Some 'theory': the groupby operation (split-apply-combine)
The "group by" concept: we want to apply the same function on subsets of your dataframe, based on some key to split the dataframe in subsets
This operation is also referred to as the "split-apply-combine" operation, involving the following steps:
Splitting the data into groups based on some criteria
Applying a function to each group independently
Combining the results into a data structure
<img src="img/splitApplyCombine.png">
Similar to SQL GROUP BY
The example of the image in pandas syntax:
End of explanation
df.groupby('key').aggregate(np.sum)  # 'sum'
df.groupby('key').sum()
Explanation: Using the filtering and reductions operations we have seen in the previous notebooks, we could do something like:
df[df['key'] == "A"].sum()
df[df['key'] == "B"].sum()
...
But pandas provides the groupby method to do this:
End of explanation
df = pd.read_csv("data/titanic.csv")
df.head()
Explanation: And many more methods are available. 
And now applying this on some real data
We go back to the titanic survival data:
End of explanation
<END_TASK>