Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python pandas box plot a single column

Tags:

pandas

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': [, ]}

like image 796
Sanyo Mn Avatar asked Oct 13 '16 16:10

Sanyo Mn


People also ask

How do I plot only one column in pandas?

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 .

How do I get one column in pandas?

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.

How do you plot a single boxplot in Python?

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.

How do you only have one column in a data frame?

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.


1 Answers

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');

enter image description here

both

df.boxplot(column=['A'], return_type='axes');

or

df.boxplot(column='A', return_type='axes');

return

enter image description here

like image 178
piRSquared Avatar answered Oct 20 '22 07:10

piRSquared