내용 미리보기

head(), tail()

head(n), tail(n) 메서드는 데이터 프레임의 앞, 뒤의 n행을 미리 보여준다. default는 5이다.

import pandas as pd

path = "03_Data\\Example\\\\auto-mpg.csv"

df = pd.read_csv(path, header=None)
df.columns = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight',
              'acceleration', 'model year', 'origin', 'name']

print(" < head > ")
print(df.head(3))
print(" < tail > ")
print(df.tail(3))
< head > 
    mpg  cylinders  ...  origin
name
0  18.0          8  ...       1  chevrolet chevelle malibu
1  15.0          8  ...       1          buick skylark 320
2  18.0          8  ...       1         plymouth satellite

[3 rows x 9 columns]
 < tail >
      mpg  cylinders  ...  origin           name      
395  32.0          4  ...       1  dodge rampage      
396  28.0          4  ...       1    ford ranger      
397  31.0          4  ...       1     chevy s-10      

[3 rows x 9 columns]

요약 정보 확인

shape : 행, 열 개수 튜플로 변환

Data Frame의 행과 열을 튜플로 반환한다.

import pandas as pd

path = "03_Data\\Example\\\\auto-mpg.csv"

df = pd.read_csv(path, header=None)
df.columns = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight',
              'acceleration', 'model year', 'origin', 'name']

print(" < shape > ")
print(df.shape)
< shape >
(398, 9)

info() : 기본정보 출력

Data Frame의 기본정보를 출력한다. 다음의 정보를 포함한다.

import pandas as pd

path = "03_Data\\Example\\\\auto-mpg.csv"

df = pd.read_csv(path, header=None)
df.columns = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight',
              'acceleration', 'model year', 'origin', 'name']

print(" < info > ")
print(df.info())