코딩뿌셔
[Pandas_02] 데이터 및 자료형 확인 본문
import pandas as pd
# 파일 불러오기(csv)
data = pd.read_csv('./data.csv')
data
name | age | sex | country | |
---|---|---|---|---|
0 | kim | 14 | man | korea |
1 | park | 22 | female | korea |
2 | lee | 34 | man | korea |
3 | jung | 44 | female | canada |
4 | gang | 31 | man | america |
# head() : 데이터 시작 부분 출력
# default의 경우 5개 행 출력
data.head(2)
name | age | sex | country | |
---|---|---|---|---|
0 | kim | 14 | man | korea |
1 | park | 22 | female | korea |
# tail() : 데이터 끝부분 출력
# default의 경우 5개 행 출력
data.tail(2)
name | age | sex | country | |
---|---|---|---|---|
3 | jung | 44 | female | canada |
4 | gang | 31 | man | america |
# 데이터 크기 정보 확인 (행개수, 열개수)
data.shape
(5, 4)
# 데이터 자료형 확인
type(data)
pandas.core.frame.DataFrame
# 데이터프레임의 모든 열 자료형 확인
data.dtypes
name object
age int64
sex object
country object
dtype: object
age int64
sex object
country object
dtype: object
# 데이터프레임 상세 정보 확인
data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 4 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 name 5 non-null object
1 age 5 non-null int64
2 sex 5 non-null object
3 country 5 non-null object
dtypes: int64(1), object(3)
memory usage: 288.0+ bytes
# 컬럼명 확인(인덱스로 추출 가능)
data.columns
Index(['name', 'age', 'sex', 'country'], dtype='object')
'Language > Python' 카테고리의 다른 글
[함수] columns.difference 지정 컬럼명 제외 후 조회하기 (0) | 2022.09.07 |
---|---|
[Pandas_03] 행과 열 추출 (0) | 2022.07.31 |
[Pandas_01] 파일 불러오기, 저장하기 (0) | 2022.07.27 |
[Basic_04] 클래스 (0) | 2022.06.14 |
[Basic_03] 함수 (0) | 2022.06.14 |
Comments