python-3.xasciiastropy

How to write an ascii table using Astropy without the column names?


I construct a table using Astropy as follows: data = astropy.table.Table(names=['Time', 'Rate (C/s)']). Then, I fill up the rows under the aforementioned columns using data.add_row. Finally, I intend to write the table in an ascii file. I do the following: astropy.io.ascii.write(data, 'filename.dat'). The output file contains the following:

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

However, I do not want the column names written in the first row as I will be using the file in another program that doesn't handle strings. My expected outcome is:

10.  25.65
20.  37.11
30.  15.10

How can I achieve the objective? I am expecting an answer using astropy only as I can do the needful using numpy.savetxt

Secondary question: In the output file, why is the second column name within quotes?


Solution

  • Use this:

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

    You can find all the supported formats here: https://docs.astropy.org/en/stable/io/ascii/index.html#supported-formats

    In the original output the second column name is in quotes because the format is "space-delimited" meaning that it uses a space character to separate the column names and column data. Without the quotes the parser would infer that there are three columns, Time, Rate and (C/s).