Reputation: 734
The below set of code previously worked well and I was able to visualise the boxplot graph well. This code was previously used in another project of mine, and it worked perfectly well. There were no changes done to this piece of code, and it is being reused here.
I have a 'df' dataframe and I am trying to create boxplots to visualise outliers. Unfortunately, the graph doesn't seem to visualise anything. I am not sure what is wrong with my set of code. Could someone please help?
df = pd.DataFrame({'TotalPrice':[1.000, 0.650, 0.0075, 0.0025, 0.200],
'Voltage':[13.47, 13.41, 13.41, 13.41, 13.41],
'ConversionFactor':[934.0, 934.0, 2580.0, 934.0, 934.0],
'Litres':[40.0, 26.0, 3.0, 1.0, 8.0]})
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
import warnings
warnings.filterwarnings("ignore")
%matplotlib inline
%pylab inline
df = pd.read_csv('dataset.csv')
fig, ax = plt.subplots(1,4, figsize = (8, 4))
ax[0].boxplot(df.TotalPrice)
ax[1].boxplot(df.Voltage)
ax[2].boxplot(df.ConversionFactor)
ax[3].boxplot(df.Litres);
Upvotes: 1
Views: 552
Reputation: 1106
If you change from inline
to notebook
, and remove your pylab reference, it will work as expected within Jupyter Notebook:
%matplotlib notebook #< not inline
# %pylab inline #< this is not needed
Upvotes: 1
Reputation: 83
You forgot to import df
. Your code returns the following error:
Populating the interactive namespace from numpy and matplotlib
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-d9ef2c853adf> in <module>()
12 fig, ax = plt.subplots(1,4, figsize = (8, 4))
13
---> 14 ax[0].boxplot(df.TotalPrice)
15 ax[1].boxplot(df.Voltage)
16 ax[2].boxplot(df.ConversionFactor)
NameError: name 'df' is not defined
Upvotes: 0