我已將我的數據讀入熊貓數據框。我希望根據兩個變量「區域」和「類型」將數據拆分爲單獨的文件。將熊貓數據框寫入csv時獲取奇怪的輸出
所以,我想有這樣的:
contents[(contents['Zone']==zone) & (contents['Type']==type)].to_csv(outfl, sep=' ', header=False, index = False, float_format='%9.3f')
奇怪的是,我的輸出是這樣的:
200 225 255 504671.321 6342290.967 " -323.271" 1 " 0.040" " 0.319" " 0.249" " 0.141" " 2.000"
202 224 254 504721.351 6342265.992 " -323.725" 1 " 0.032" " 0.254" " 0.258" " 0.127" " 2.000"
200 225 254 504671.321 6342290.967 " -323.350" 1 " 0.038" " 0.376" " 0.243" " 0.137" " 2.000"
201 225 254 504696.336 6342290.967 " -323.593" 1 " 0.035" " 0.359" " 0.249" " 0.128" " 2.000"
爲什麼這些引號字符出現?我不想讓他們(obv),因爲我試圖創建一個空格分隔的輸出文件。好像我正在做的float_format錯誤...但不知道是什麼?
print contents.info()
產量:
編輯在別人的請求添加信息
<class 'pandas.core.frame.DataFrame'>
Int64Index: 233976 entries, 0 to 233975
Data columns (total 12 columns):
I 233976 non-null int64
J 233976 non-null int64
K 233976 non-null int64
X 233976 non-null float64
Y 233976 non-null float64
Z 233976 non-null float64
Type 233976 non-null int64
VMI_LVMI 233976 non-null float64
SWT 233976 non-null float64
PHIT 233976 non-null float64
VCLA 233976 non-null float64
Zone 233976 non-null float64
dtypes: float64(8), int64(4)
memory usage: 23.2 MB
None
@DSM我已更新我的文章以回答您的問題。 –