취미와 밥줄사이

[Pandas] pd.read_csv - 파라미터 사용법 본문

Python/Pandas

[Pandas] pd.read_csv - 파라미터 사용법

취미와 밥줄사이 2021. 5. 12. 17:58

 

 

 

판다스의 데이터 프레임으로 csv파일을 불러올 때 사용하는 명령어인 pd.read_csv() 파라미터 사용법을 정리한 게시물입니다.

 

 

 

 

 

 

 

 

 

1. csv 파일 불러오기: pd.read_csv( filepath_or_buffer = :)


 

 

 

2. n번째 행까지 불러오기: nrows = 


 

3.  컬럼을 index로 지정: index_col =





 

 

4.  컬럼(열 이름)으로 사용할 행 지정: header =


 

 

 

5. 파일 형식에 따른 구분자 지정:  sep = 


csv 파일의 경우  sep = ','   

tsv 파일의 경우  sep = '\t'

 

 

 

6. 결측값을 불러올지 여부:  na_filter = 


  • 결측치를 불러온다: na_filter = True
  • 결측치를 불러오지 않는다: na_filter = False

 

 

 

7. 데이터프레임을 CSV 파일로 저장하기: pd.to_csv( '파일명.csv')


파일명만 작성한 경우에는 현재 작업하는 공간의 주소로 저장되고 절대 경로를 입력한 경우 절대경로의 주소에 저장됩니다.

 

 

 

Reference


pandas.pydata.org/docs/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

 

https://pandas.pydata.org/about/citing.html

 

pandas - Python Data Analysis Library

Citing and logo Citing pandas If you use pandas for a scientific publication, we would appreciate citations to the published software and the following paper: pandas on Zenodo, Please find us on Zenodo and replace with the citation for the version you are

pandas.pydata.org