Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using <code>astropy.io.ascii</code> you should be able to read your file relatively easily:</p> <pre><code>from astropy.io import ascii # Give names for ALL of the columns, as there is no easy way to skip columns # for a table with no column header. colnames = ('sn', 'gal_name1', 'gal_name2', 'year', 'month', 'day', ...) table = ascii.read('sn_full.txt', Reader=ascii.NoHeader, names=colnames) </code></pre> <p>This gives you a table with all of the data columns. The fact that you have some columns you don't need is not a problem unless the table is mega-rows long. For the table you showed you don't need to specify the dtypes explicitly since <code>io.ascii.read</code> will figure them out correctly.</p> <p>One slight catch here is that the table you've shown is really a fixed width table, meaning that all the columns line up vertically. Notice that the first row begins with <code>1998S NGC 3877</code>. As long as every row has the same pattern with three space-delimited columns indicating the supernova name and the galaxy name as two words, then you're fine. But if any of the galaxy names are a single word then the parsing will fail. I suspect that if the IDL <code>readcol</code> is working then the corresponding <code>io.ascii</code> version should work out of the box. If not then <code>io.ascii</code> has a way of reading fixed width tables where you supply the column names and positions explicitly.</p> <p>[EDIT] Looks like in this case a fixed width reader is needed to inform the parser how to split the columns instead of just using space as delimiter. So basically you need to add two rows at the top of the table file, where the first one gives the column names and the second has dashes that indicate the span of each column:</p> <pre><code> a b c ---- ------------ ------ 1.2 hello there 2 2.4 worlds 3 </code></pre> <p>It's also possible in <code>astropy.io.ascii</code> to just specify by code the start and stop position of each column if you don't have the option of modifying the input data file, e.g.:</p> <pre><code>&gt;&gt;&gt; ascii.read(table, Reader=ascii.FixedWidthNoHeader, names=('Name', 'Phone', 'TCP'), col_starts=(0, 9, 18), col_ends=(5, 17, 28), ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload