다음 데이터가 포함 된 Pandas 데이터 프레임이 있습니다.
0 5
1 7
2 3
첫 번째 열은 색인입니다.
출력이 다음과 같이 보이도록 CSV 파일 (공백으로 구분)에 기록하는 가장 쉬운 방법은 무엇입니까?
|index 0 |features 5
|index 1 |features 7
|index 2 |features 3
csv 파일은 다음과 같은 파일을 작성하는 것을 의미합니다.
test.to_csv('test_map2.txt', sep=' ', header=None, index=False)
다음과 같이 진행할 수 있습니다.
test.index = test.index.map(lambda x:"|index " + str(x))
test.ix[:,0] = test.ix[:,0].apply(lambda x:'|features ' + str(x))
test.to_csv('test_map2.txt', sep=' ', header=None, index=False)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다