matplotlib boxplot to plot < > greater than and less than a certain value

Viewed 569

Need a method for matplotlib to plot a boxplot that shows '<=' and '>' values.

#Data Exploration
#Exploring the age variable

> summary (TrainSet$age)
Min. 1st Qu. Median Mean 3rd Qu. Max.
17.00 28.00 37.00 38.44 47.00 90.00

#Boxplot for age variable
boxplot (age ~ incomelevel, data = TrainSet,
main = "Income levels based on the Age of an individual",
xlab = "Income Level", ylab = "Age", col = "salmon")

The above piece of code is written in R that does the same as my question; Displays the income levels above and below 50k against the age of the individual. I want it converted into python matplotlib code.

1 Answers

Still pretty confused by what is the question, but maybe take it from here:

from matplotlib import pyplot as plt
import pandas as pd

colnames= ['age','workclass','fnlwgt','edu','edu_num','maritial','occ','relationship',
'race','sex','capital-gain','capital-loss','hours-per-week','country','label']

df = pd.read_csv("http://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data",names=colnames)
df.boxplot(column='age',by='label')

enter image description here

Or if using seaborn:

import seaborn as sns
sns.boxplot(x='label',y='age',data=df)

enter image description here

Related