DataFrame와 메서드

스프레드시트 사용자를 위한 Python

Chris Cardillo

Data Scientist

이전 단계 복습

import pandas as pd

fruit = pd.read_excel('fruit.xlsx')

print(fruit)

단순 과일 전체 데이터셋.png

스프레드시트 사용자를 위한 Python

pandas DataFrame의 구조

단순 과일 전체 데이터셋.png

스프레드시트 사용자를 위한 Python

pandas DataFrame의 구조

단순 과일 df 열.png

스프레드시트 사용자를 위한 Python

pandas DataFrame의 구조

단순 과일 df 수치형 열.png

스프레드시트 사용자를 위한 Python

pandas DataFrame의 구조

단순 과일 df 객체-문자열 열.png

스프레드시트 사용자를 위한 Python

pandas DataFrame의 구조

단순 과일 df 행 1.png

스프레드시트 사용자를 위한 Python

pandas DataFrame의 구조

단순 과일 df 행 2.png

스프레드시트 사용자를 위한 Python

pandas DataFrame의 구조

단순 과일 df 인덱스.png

스프레드시트 사용자를 위한 Python

DataFrame 메서드

  • .head()
  • .info()
  • .describe()
  • .sort_values()
스프레드시트 사용자를 위한 Python

.head() 메서드

import pandas as pd

fruit = pd.read_excel('fruit.xlsx')

print(fruit.head())

단순 과일 df head.png

스프레드시트 사용자를 위한 Python

.head() 메서드

import pandas as pd

fruit = pd.read_excel('fruit.xlsx')

print(fruit.head(2))

단순 과일 df head 인수 포함.png

스프레드시트 사용자를 위한 Python

.info() 메서드

import pandas as pd

fruit = pd.read_excel('fruit.xlsx')

print(fruit.info())
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 8 entries, 0 to 7
Data columns (total 3 columns):
 #   Column     Non-Null Count  Dtype  
 --  ------     --------------  -----  
 0   name       8 non-null      object 
 1   color      8 non-null      object 
 2   price_usd  8 non-null      float64
dtypes: float64(1), object(2)
memory usage: 272.0+ bytes
스프레드시트 사용자를 위한 Python

.describe() 메서드

import pandas as pd

fruit = pd.read_excel('fruit.xlsx')

print(fruit.describe())

단순 과일 df describe 메서드.png

스프레드시트 사용자를 위한 Python

.sort_values() 메서드

import pandas as pd

fruit = pd.read_excel('fruit.xlsx')

fruit = fruit.sort_values('name')
fruit = fruit.reset_index(drop=True)

print(fruit)

단순 과일 df 이름 오름차순 정렬.png

스프레드시트 사용자를 위한 Python

.sort_values() 메서드

import pandas as pd

fruit = pd.read_excel('fruit.xlsx')

fruit = fruit.sort_values('price_usd', ascending=False)
fruit = fruit.reset_index(drop=True)

print(fruit.head(3))

단순 과일 df 가격 내림차순 정렬 head 3.png

스프레드시트 사용자를 위한 Python

이제 직접 해 보세요!

스프레드시트 사용자를 위한 Python

Preparing Video For Download...