반응형
이전 포스팅에서 pandas를 사용하여 파일을 읽고 쓰는 방법을 소개한 적이 있다.
자세한 내용은 아래 참고 포스팅을 확인 바란다.
이번 포스팅에서는 pandas 활용이 아닌 순수 python으로 파일을 읽는 방법을 소개하려고 한다.
파일 읽기
file = open('file.txt','r')
while True:
ll = file.readline()
if not ll : break;
file.close()
파일 쓰기
file = open('file.txt','w')
file.write('text')
file.close()
이렇게 파일을 읽고 쓸수 있다.
참고 포스팅
https://thenicesj.tistory.com/386
read_csv()
csv파일 읽기 pandas를 이용해 csv 파일을 불러오기 위해서는 아래와 같이 pandas를 먼저 import 그리고 약어로 지정한 pd를 사용하여 read_csv함수를 통해 csv 파일 import pandas as pd data = pd.read_csv('파일경로/
thenicesj.tistory.com
반응형
'IT > Python' 카테고리의 다른 글
글읽기, 수정하기 (read, readline, readlines) (15) | 2023.02.28 |
---|---|
파이선 함수 선언 (15) | 2023.01.17 |
단어가 영어인지 아닌지 확인법 (8) | 2022.12.29 |
모듈 경로 알아내기 (15) | 2022.12.27 |
SyntaxError: Non-UTF-8 code starting with '\xea' in file <FilePath> but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details (13) | 2022.12.26 |
댓글