import pandas
from matplotlib import pyplot
df = pandas.read_csv("titanic.csv")
df.dropna(inplace=True)
pyplot.boxplot(x=df["age"])
pyplot.savefig("matplotlib-box-plot.png")
pyplot.close()
Here, we are first reading the “titanic” dataset. The dataset contains various information, such as age of the passengers, whether the passenger survived, etc. In this example, we are drawing a box and whisker plot on the ages of the passengers.
Please note that the age column in the titanic dataset contains null values. So, for simplicity, we are first removing all rows from the dataset that contains null values. And then, we are passing the df[“age”] column as the x parameter in the pyplot.boxplot() function.
The resulting box and whisker plot looks like the following:

Please note that the lower whisker indicates the minimum age of the passengers. The upper whisker indicates the maximum age of the passengers. The box is drawn from the first quartile to the third quartile or the 25th percentile to the 75th percentile. And the orange line in the middle of the box indicates the median age.








































0 Comments