Analyzing Titanic data with plotnine
We will now demonstrate the simplicity of using plotnine for recurring tasks such as exploratory analysis.
First, you need to install the plotnine
package. Here are the steps to do that:
- Open Anaconda Prompt.
- Switch to your
pbi_powerqery_env
environment by entering this command:conda activate pbi_powerqery_env
. - There are two ways to install plotnine: either install the package with the default options with a simple
pip install plotnine==0.12.4
or install some extra features withpip install plotnine[all]==0.12.4
(the extra packages installed arescikit-learn
andscikit-misc
for loess and Gaussian smoothing). The default installation is sufficient for the code you will find in this chapter.
Then, you can import the necessary libraries and functions and load the Titanic data into the df
variable with the following code:
import pandas as pd
from plotnine import (
options, theme_tufte, ggplot, aes, geom_bar...