Language&Framework/Python

[pandas] 파일 열기 모드(mode='w')

JUNG씨 2023. 2. 28. 14:23
os.path.exists(new_file_path):
            with pd.ExcelWriter(new_file_path, mode='w') as writer:

 

위의 코드처럼 excel파일로 저장하려고 할 때, 

파일이 이미 존재하는 경우에도 에러가 나지 않고 덮어쓰기를 하고 싶다면, mode='w'로 설정하면 된다.

 

mode='w'는 write 모드로 파일을 열기 때문에, 존재하는 파일일 경우에도 덮어쓰기를 한다.

 

 

 

python에서의 파일 열기모드에 대해 정리해놓은 링크이다.

https://www.delftstack.com/ko/howto/python/python-open-modes/

 

Python 파일 열기 모드

이 튜토리얼은 모든 파이썬 개방 모드가 무엇인지 보여줍니다

www.delftstack.com