[python] dataframe to text 텍스트파일저장


[python] dataframe to text 텍스트파일저장

dataframe 을 text file 로 저장하고 싶을때 쓰는 코드 입니다. 여러가지 방법이 있겠지만 open( ) 과 to_string( )을 이용한 예제 입니다. dict_data = {'col1':[1,2,3,4,5], 'col2':[11,22,33,44,55], 'col3':[111,222,333,444,555]} df = pd.DataFrame(dict_data) print(df) col1 col2 col3 0 1 11 111 1 2 22 222 2 3 33 333 3 4 44 444 4 5 55 555 열 이름은 col1,2,3 행이름은 0,1,2,3,4 로 구성된 dataframe 입니다 이 df 를 텍스트 파일로 저장하고 싶은 경우인데, 1.텍스트 파일 경로지정 2. 파일열기 3. df.to_string() 으로 파일쓰기 4. 파일닫기 순서로 진행합니다. newfilename1 = 'D:\\test_txt1.txt' #file open mode: a, w, r, a+...


#dataframe #dftotext #python #textfile #to_string #열이름삭제 #주니퍼가든 #행이름삭제

원문링크 : [python] dataframe to text 텍스트파일저장