Convert a .sav file to .csv file in Python

前端 未结 4 565
面向向阳花
面向向阳花 2021-01-17 07:28

I want to convert the contents of *.sav file into a *.csv file in Python. I have written the following lines of code to access the details of variables in *.sav file. Now, I

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-17 07:50

    I am working on it and, for the moment, this is my 'poor' solution:

    First I import module savReaderWriter to convert .sav file into structured array Second I import module numpy to convert structured array into csv:

    import savReaderWriter 
    import numpy as np
    
    reader_np = savReaderWriter.SavReaderNp("infile.sav")
    array = reader_np.to_structured_array("outfile.dat") 
    np.savetxt("outfile2.csv", array, delimiter=",")
    reader_np.close()
    

    The problem is that I lose name atributes during conversion. I will try to solve the problem.

提交回复
热议问题