如何使用Astropy编写没有列名的ascii表?

问题描述 投票:0回答:1

我使用 Astropy 构建了一个表,如下所示:

data = astropy.table.Table(names=['Time', 'Rate (C/s)'])
。然后,我使用
data.add_row
填充上述列下的行。最后,我打算将表写入ascii文件中。我执行以下操作:
astropy.io.ascii.write(data, 'filename.dat')
。输出文件包含以下内容:

Time "Rate (C/s)"
10.  25.65
20.  37.11
30.  15.10

但是,我不希望将列名称写在第一行,因为我将在另一个不处理字符串的程序中使用该文件。我的预期结果是:

10.  25.65
20.  37.11
30.  15.10

如何才能达到目标?我期待使用 astropy 得到答案,因为我可以使用

numpy.savetxt

完成所需的工作

第二个问题:在输出文件中,为什么第二列名称包含在引号内?

python-3.x ascii astropy
1个回答
0
投票

使用这个:

astropy.io.ascii.write(data, 'filename.dat', format="no_header")

您可以在这里找到所有支持的格式:https://docs.astropy.org/en/stable/io/ascii/index.html#supported-formats

在原始输出中,第二列名称用引号引起来,因为格式是“空格分隔”,这意味着它使用空格字符来分隔列名称和列数据。如果没有引号,解析器将推断存在三列:

Time
Rate
(C/s)

© www.soinside.com 2019 - 2024. All rights reserved.