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]
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)
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())