Pandas dataframe에서 상자 그림을 만드는 방법


다음 구문을 사용하여 Pandas DataFrame에서 상자 그림을 만들 수 있습니다.

 #create boxplot of one column
df. boxplot (column=[' col1 '])

#create boxplot of multiple columns
df. boxplot (column=[' col1 ', ' col2 '])

#create boxplot grouped by one column
df. boxplot (column=[' col1 '], by=' col2 ') 

다음 예에서는 다음 DataFrame에서 실제로 이 구문을 사용하는 방법을 보여줍니다.

 import pandas as pd

#createDataFrame
df = pd. DataFrame ({' conference ': ['A', 'A', 'A', 'B', 'B', 'B'],
                   ' points ': [5, 7, 7, 9, 12, 9],
                   ' assists ': [11, 8, 10, 6, 6, 5],
                   ' rebounds ': [4, 2, 5, 8, 6, 11],})

#view DataFrame
df

예 1: 열의 상자 그림

다음 코드는 Pandas DataFrame의 열에 대한 상자 그림을 만드는 방법을 보여줍니다.

 df. boxplot (column=[' points '], grid= False , color=' black ')

예 2: 여러 열의 상자 그림

다음 코드는 Pandas DataFrame의 여러 열에 대한 상자 그림을 만드는 방법을 보여줍니다.

 df. boxplot (column=[' points ', ' assists '], grid= False , color=' black ') 

예 3: 하나의 열로 그룹화된 상자 그림

다음 코드는 Pandas DataFrame의 열로 그룹화된 상자 그림을 만드는 방법을 보여줍니다.

 df. boxplot (column=[' points '], by=' conference ', grid= False , color=' black ') 

추가 리소스

Pandas: 여러 계열을 그리는 방법
Pandas: 막대 차트에 여러 열을 그리는 방법

의견을 추가하다

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다