Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 需要使用ascii编写.dat文件的帮助吗_Python_Ascii_Astropy - Fatal编程技术网

Python 需要使用ascii编写.dat文件的帮助吗

Python 需要使用ascii编写.dat文件的帮助吗,python,ascii,astropy,Python,Ascii,Astropy,目前,我正在尝试在python anaconda中使用astropy.io.ascii来编写一个.dat文件,其中包含我已经从另一个.dat文件中使用ascii读取的数据。我在预先存在的文件中定义了一个特定的表作为数据,数据的问题是我需要将第一列乘以系数101325来改变它的单位,我需要四列中的第四列完全消失。我把第一列定义为压强,转换了单位,然后把另外两列定义为海拔高度和温度。我能用ascii的写函数告诉它写一个包含我定义的三列的.dat文件吗?我该怎么做呢?下面是使我能够定义这三列数据的代码

目前,我正在尝试在python anaconda中使用astropy.io.ascii来编写一个.dat文件,其中包含我已经从另一个.dat文件中使用ascii读取的数据。我在预先存在的文件中定义了一个特定的表作为数据,数据的问题是我需要将第一列乘以系数101325来改变它的单位,我需要四列中的第四列完全消失。我把第一列定义为压强,转换了单位,然后把另外两列定义为海拔高度和温度。我能用ascii的写函数告诉它写一个包含我定义的三列的.dat文件吗?我该怎么做呢?下面是使我能够定义这三列数据的代码:

from astropy.io import ascii
Data=ascii.read('output_couple_121_100.dat',guess=False,header_start=384,data_start=385,data_end=485,delimiter=' ')
Pressure_pa=Data['P(atm)'][:}*101325
Altitude_km=Data['Alt(km)'][:]
Temperature_K=Data['T'][:]

现在我想我可以使用ascii.write,将一个带有压力、海拔高度和温度的.dat文件写入同一个文件,有什么方法可以做到这一点吗?

所以我想我找到了答案!我将创建一个更通用的版本以适合其他人

    from astropy.io import ascii
    Data=ascii.read('filename.dat',guess=False,header_start=1,data_start=2,data_end=10,delimiter=' ')
    #above: defining Data as a certain section of a .dat file beginning at line 2 through 10 with headers in line 1
    ascii.write(Data,'new_desired_file_name.dat',names=['col1','col2','col3','col4'],exclude_names=['col3'],delimiter=' ')
    #above: telling ascii to take Data and creat a .dat file with it, when defining the names, define a name for every column in Data and then use the exclude_names command to tell it not to include those specific columns

那么,您的代码、实际输入/输出和期望的行为在哪里?目前还不清楚你在问什么,看看@AzatIbrakov,我编辑了这个问题,试图更好地澄清它,对不起,我对这个社区相当陌生。我刚在大学这学期开始使用python,我正在用它做天体物理研究。不管怎么说,我包括了使我达到我所处位置的代码,我尝试了几种不同的方法来编写文件,如果我键入ascii.writePressure_pa,sys.stdout,它将只输出该列中的数据,这与其他两列相同。我试着把它们都写在一起,但我得到了一个错误信息:不可破坏的文本:列正确地标记这样的问题真的很重要。如果没有提及astropy,其余的都没有任何意义。astropy.io.ascii与一般的ascii编解码器有很大不同。@Blckknght我会记住这一点,以便将来标记,关于使用astropy.io.ascii编写.dat文件有什么想法吗?不,对不起,我对astropy一无所知。你检查过astropy.io.ascii文件了吗?它期望什么样的论点?