Python/Pandas

[Python] Pandas : csv 파일 불러오기

다애루 2021. 4. 17. 13:10

Pandas 라이브러리에서 csv 파일을 불러오는 함수를 알아보자.

pandas를 이용해 csv 파일을 불러오기 위해서는
pandas를 먼저 import 해야한다.
일반적으로 pd라는 약어를 많이 사용하며,
read_csv 라는 함수를 통해 csv 파일을 불러 올 수 있다.

 


c s v ?


CSV는 Comma Seperated Value의 약자로
몇 가지 필드를 쉼표(comma)로 구분한 텍스트 데이터 및 텍스트 파일이다.
확장자는 .csv 이며 MIME 형식은 text/csv 이다.
오래전부터 스프레드시트나 데이터베이스 소프트웨어에서 많이 사용되었고
세부적인 구현은 소프트웨어에 따라서 다르다.

*예를 들면 아래와 같이 쓰여 있는 텍스트 파일을 말한다.

이름, 성별, 나이 김영민, 남자, 27 김영우, 남자, 21

read.csv(   )


pd.read_csv ('파일명.csv', encoding='euc-kr', index_col='컬럼명')

data = pd.read_csv("score.csv", encoding='euc-kr', index_col='과목')

 


파라미터


위의 코드에서 봤다시피 read_csv 함수는
다양한 파라미터가 존재한다.
일반적으로 많이 사용하는 파라미터에는
다음과 같은 것들이 있다.

 

 

 

아래의 링크에서 더욱 자세하게 확인할 수 있다.
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html

 

pandas.read_csv — pandas 1.2.4 documentation

Delimiter to use. If sep is None, the C engine cannot automatically detect the separator, but the Python parsing engine can, meaning the latter will be used and automatically detect the separator by Python’s builtin sniffer tool, csv.Sniffer. In addition

pandas.pydata.org

 

 


프로그래밍 공부를 위해 여러 자료들을 토대로 작성한 기록입니다.

개인 공부에만 사용해주시고, 상업적인 활용과 재배포를 금지합니다.