데이터 프레임의 인덱스 만 파일에 저장하려고합니다. 여기에 내가 무엇을 시도했다입니다 :파일에 팬더 데이터 프레임 인덱스 저장
A)
np.savetxt("file_name", df.index.values)
반환 :
TypeError: Mismatch between array dtype ('object') and format specifier ('%.18e')
B)
df.index.values.tofile("file_name")
반환 :
IOError: cannot write object arrays to a file in binary mode
C)
with open("file_name","w") as f:
f.write("\n".join(df_1_indexes.values.tolist()))
누군가가 설명해 주시겠습니까 왜 A) 및 B) 실패? 나는 잃어 버렸다. 당신이 문자열이나 색인에 object
의 someother 유형을 가지고 있기 때문에
건배
어떤 종류의 개체가 색인을 구성하는지 알 수 있습니다. 'df.head(). index.values'와'type (df.index)'를 게시하십시오. – unutbu
'array ([ 'A1BG', 'A1BG-AS1', 'A2LD1', 'A2M', 'A2ML1'], dtype = object)'및'pandas.indexes.base.Index'를 각각 나타냅니다. – WindChimes