기계는 거짓말하지 않는다

Python DataFrame 특정 columns 추출 본문

Python

Python DataFrame 특정 columns 추출

KillinTime 2021. 10. 5. 15:18

DataFrame에서 특정 column만 추출

import numpy as np
import pandas as pd

dataFrame = pd.read_csv("data.csv", delimiter=",", encoding="euc-kr", skiprows=1)	# 첫 행이 columns이면 skiprows 불필요

select_cols = ["col1", "col2", "col3", "col4"] # 특정 column의 field name
another_cols = ["col5", "col6"]

select_cols_frame = dataFrame[select_cols]
another_cols_frame = dataFrame[another_cols]

print(select_cols_frame)

# numpy 배열로
select_cols_numpy = select_cols_frame.to_numpy()
Comments