Getting visualizations with Python
In this section, we are going to go over visualizations of the data in Python, analogous to the preceding R section. We will use plotnine
to have visualizations similar to those created in R using ggplot2
and provide interpretations of the results.
Getting the data
Like in the earlier chapters, we will load the data using pandas
. Just like before, the path to the XLSX file may be different for you from what I have, so adjust the filepath
accordingly:
import pandas as pd # Define the file path (may be different for you) file_path = "./Chapter 12/diamonds.xlsx" # Load the dataset into a pandas DataFrame df = pd.read_excel(file_path) # Display the first few rows of the DataFrame print(df.head())
Note that we use the raw diamonds
dataset without spitting it first and then recombining it, as it was done in the R part of the chapter.
Visualizing the data
Once we have our data loaded, we can use plotnine
to create visualizations...