I'm trying to box plot a single column of the dataframe using pandas. However, I got no figure but a text output as shown below: thanks
df.boxplot(column=['crim'])
"{'medians': [], 'fliers' [, ], 'whiskers': [, ], 'boxes': [], 'caps': [, ]}
To plot a specific column, use the selection method of the subset data tutorial in combination with the plot() method. Hence, the plot() method works on both Series and DataFrame .
You can use the loc and iloc functions to access columns in a Pandas DataFrame. Let's see how. If we wanted to access a certain column in our DataFrame, for example the Grades column, we could simply use the loc function and specify the name of the column in order to retrieve it.
Box Plot for Single variable To draw a box plot with Seaborn, the boxplot() function is used. You can either pass the full dataframe column names to the x or y parameters or you can simply specify the column names in the x and y parameters and then specify the dataframe name in the dataset parameter.
Selecting columns based on their name This is the most basic way to select a single column from a dataframe, just put the string name of the column in brackets. Returns a pandas series. Passing a list in the brackets lets you select multiple columns at the same time.
versions
import sys
import pandas as pd
import numpy as np
print(pd.__version__)
print(sys.version)
0.18.1
2.7.12 |Anaconda 4.0.0 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)]
Also got same results with
print(sys.version)
3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]
consider the df
df = pd.DataFrame(np.random.randn(100, 5), columns=list('ABCDE'))
df.boxplot(return_type='axes');
both
df.boxplot(column=['A'], return_type='axes');
or
df.boxplot(column='A', return_type='axes');
return
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With