Pandas DataFrame describe() 메서드

Beginner

소개

이 랩에서는 Pandas 라이브러리의 describe() 메서드를 사용하여 DataFrame 에 대한 기술 통계를 생성하는 방법을 배우게 됩니다. describe() 메서드는 숫자 열에 대한 count, mean (평균), standard deviation (표준 편차), minimum (최소값), maximum (최대값), percentiles (백분위수) 와 같은 다양한 통계적 측정값을 계산합니다. 또한 object (객체) 데이터 유형의 열에 대한 요약 통계도 제공합니다.

VM 팁

VM 시작이 완료되면 왼쪽 상단을 클릭하여 Notebook 탭으로 전환하여 실습을 위해 Jupyter Notebook에 액세스하십시오.

때로는 Jupyter Notebook 이 로딩을 완료하는 데 몇 초 정도 기다려야 할 수 있습니다. Jupyter Notebook 의 제한 사항으로 인해 작업의 유효성 검사는 자동화될 수 없습니다.

학습 중에 문제가 발생하면 언제든지 Labby 에게 문의하십시오. 세션 후 피드백을 제공해주시면 즉시 문제를 해결해 드리겠습니다.

필요한 라이브러리를 가져오고 DataFrame 생성하기

먼저, import 키워드를 사용하여 Pandas 라이브러리를 가져옵니다. 샘플 데이터를 사용하여 pd.DataFrame() 메서드로 DataFrame 을 생성합니다.

import pandas as pd

## Create a DataFrame
df = pd.DataFrame([['Abhishek', 100, 'Science', 90],
                   ['Anurag', 101, 'Science', 85],
                   ['Chetan', 103, 'Maths', 75]],
                  columns=['Name', 'Roll No', 'Subject', 'Marks'])

describe() 메서드를 사용하여 DataFrame 설명하기

DataFrame 을 설명하려면 DataFrame 객체에 대해 describe() 메서드를 사용합니다.

## Describe the DataFrame
description = df.describe()

## Print the description
print(description)

DataFrame 의 모든 열 설명

DataFrame 의 모든 열, 즉 숫자형 및 객체 데이터 유형을 모두 설명하려면 describe() 메서드에서 include='all' 매개변수를 사용합니다.

## Describe all columns of the DataFrame
description_all_columns = df.describe(include='all')

## Print the description of all columns
print(description_all_columns)

DataFrame 의 특정 열 설명

DataFrame 의 특정 열을 설명하려면 속성으로 접근하여 describe() 메서드를 사용합니다.

## Describe a specific column of the DataFrame
marks_description = df.Marks.describe()

## Print the description of the 'Marks' column
print(marks_description)

설명에서 숫자 열 제외

설명에서 숫자형 열을 제외하려면 describe() 메서드에서 exclude=np.number 매개변수를 사용합니다.

import numpy as np

## Exclude numeric columns from the description
description_exclude_numeric = df.describe(exclude=np.number)

## Print the description excluding numeric columns
print(description_exclude_numeric)

None 값을 가진 DataFrame 설명

None 값을 포함하는 DataFrame 을 설명하려면 describe() 메서드가 적절하게 처리합니다.

## Create a DataFrame with None values
df_with_none = pd.DataFrame([['Abhishek', 101, 'Science', None],
                             ['Anurag', None, 'Science', 85],
                             ['Chetan', None, 'Maths', 75]],
                            columns=['Name', 'Roll No', 'Subject', 'Marks'])

## Describe the DataFrame with None values
description_with_none = df_with_none.describe()

## Print the description of the DataFrame with None values
print(description_with_none)

요약

축하합니다! 이 랩에서는 Pandas 의 describe() 메서드를 사용하여 DataFrame 에 대한 기술 통계를 생성하는 방법을 배웠습니다. 이 메서드를 사용하여 데이터 세트의 분포에 대한 중심 경향, 분산 및 모양에 대한 귀중한 통찰력을 얻을 수 있습니다. describe() 메서드는 데이터 분석 및 탐색을 위한 강력한 도구입니다. 즐거운 코딩 되세요!