0

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?

1 Answer 1

0

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.