Skip to content

Instantly share code, notes, and snippets.

@autocorr
Created March 19, 2016 22:15
Show Gist options
  • Save autocorr/45728bf378371150aef1 to your computer and use it in GitHub Desktop.
Save autocorr/45728bf378371150aef1 to your computer and use it in GitHub Desktop.
Reading a CDS fixed width table into a pandas dataframe
import pandas as pd
from astropy import table
# use the astropy table reader method to read the file and convert
# to a `pandas.DataFrame`
df = table.Table.read('table1.txt', format='ascii.cds').to_pandas()
df.to_csv('table1.csv', index=False)
# when reading the files, remember to set the index column for
# matching and other things
df = pd.read_csv('table1.csv', index_col='Seq') # index for that table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment