我想將* .sav文件的內容轉換爲Python中的* .csv文件。我寫了下面幾行代碼來訪問* .sav文件中變量的詳細信息。現在,我不是我怎麼能訪問的可變數據寫入到與標題將.sav文件轉換爲Python中的.csv文件
import scipy.io as spio
on2file = 'ON2_2015_112m_220415.sav'
on2data = spio.readsav(on2file, python_dict=True, verbose=True)
以下是結果,當我運行的代碼上面的行.csv文件明確:
IDL Save file is compressed
-> expanding to /var/folders/z4/r3844ql123jgkq1ztdr4jxrm0000gn/T/tmpVE_Iz6.sav
--------------------------------------------------
Date: Mon Feb 15 20:41:02 2016
User: zhangy1
Host: augur
--------------------------------------------------
Format: 9
Architecture: x86_64
Operating System: linux
IDL Version: 7.0
--------------------------------------------------
Successfully read 11 records of which:
- 7 are of type VARIABLE
- 1 are of type TIMESTAMP
- 1 are of type NOTICE
- 1 are of type VERSION
--------------------------------------------------
Available variables:
- saved_data [<class 'numpy.recarray'>]
- on2_grid_smooth [<type 'numpy.ndarray'>]
- d_lat [<type 'numpy.float32'>]
- on2_grid [<type 'numpy.ndarray'>]
- doy [<type 'str'>]
- year [<type 'str'>]
- d_lon [<type 'numpy.float32'>]
--------------------------------------------------
任何人都可以告訴我如何將所有可變數據寫入.csv文件?
我想寫的變量(年,DOY,d_lon,d_lat,on2_grid,on2_grid_smooth)到CSV或ASCII文件應該以下列方式看:
longitude, latitude, on2_grid, on2_grid_smooth # header
0.0,0.0,0.0,0.0
0.0,0.0,0.0,0.0
0.0,0.0,0.0,0.0
0.0,0.0,0.0,0.0
.....
的「形狀on2_grid 「和」on2_grid_smooth「變量是相同的並且是(101,202)。兩者都是「numpy.ndarray」類型。
你想寫哪個變量?什麼是csv應該是什麼樣子?我們還應該知道要編寫的數組的形狀和dtype。 – hpaulj