import pandas as pd
data = pd.read_csv('data/sample.txt', sep='|')
data
obsid | designation | obsdate | lmjd | planid | spid | fiberid | ra | dec | snru | ... | mag5 | mag6 | mag7 | tsource | fibertype | tfrom | t_info | rv | z | z_err | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 101001 | J220848.54-020324.3 | 2011-10-24 | 55859 | F5902 | 1 | 1 | 332.202274 | -2.056767 | 2.23 | ... | 15.97 | 99 | 99 | JF_LEGAS_S | Obj | SDSS_S | NaN | -23.069030 | NaN | 0.000003 |
1 | 101002 | J220953.17-020506.0 | 2011-10-24 | 55859 | F5902 | 1 | 2 | 332.471576 | -2.085015 | 2.00 | ... | 15.67 | 99 | 99 | JF_LEGAS_S | Obj | SDSS_S | NaN | 27.100000 | NaN | 0.000178 |
2 | 101008 | J220928.49-015720.7 | 2011-10-24 | 55859 | F5902 | 1 | 8 | 332.368745 | -1.955771 | 1.84 | ... | 15.64 | 99 | 99 | JF_LEGAS_S | Obj | SDSS_S | NaN | 25.038666 | NaN | 0.000003 |
3 | 101009 | J220849.59-015207.1 | 2011-10-24 | 55859 | F5902 | 1 | 9 | 332.206665 | -1.868653 | 1.86 | ... | 16.25 | 99 | 99 | JF_LEGAS_S | Obj | SDSS_S | NaN | -22.169652 | NaN | 0.000005 |
4 | 101016 | J220923.69-020809.9 | 2011-10-24 | 55859 | F5902 | 1 | 16 | 332.348725 | -2.136096 | 2.17 | ... | 14.62 | 99 | 99 | JF_LEGAS_S | Obj | SDSS_S | NaN | -6.631409 | NaN | 0.000001 |
5 | 101017 | J220946.66-015526.5 | 2011-10-24 | 55859 | F5902 | 1 | 17 | 332.444417 | -1.924046 | 2.60 | ... | 15.65 | 99 | 99 | JF_LEGAS_S | Obj | SDSS_S | NaN | -2.461296 | NaN | 0.000002 |
6 | 101020 | J220853.37-015915.4 | 2011-10-24 | 55859 | F5902 | 1 | 20 | 332.222379 | -1.987626 | 2.65 | ... | 15.27 | 99 | 99 | JF_LEGAS_S | Obj | SDSS_S | NaN | 10.849489 | NaN | 0.000008 |
7 | 101021 | J220924.33-014833.5 | 2011-10-24 | 55859 | F5902 | 1 | 21 | 332.351381 | -1.809333 | 6.05 | ... | 14.92 | 99 | 99 | JF_LEGAS_S | Obj | SDSS_S | NaN | -17.918595 | NaN | 0.000004 |
8 | 101023 | J221001.52-020100.8 | 2011-10-24 | 55859 | F5902 | 1 | 23 | 332.506374 | -2.016900 | 2.35 | ... | 16.12 | 99 | 99 | JF_LEGAS_S | Obj | SDSS_S | NaN | 52.658545 | NaN | 0.000002 |
9 rows × 32 columns
data['obsid']
data['designation']
data['obsdate']
0 2011-10-24 1 2011-10-24 2 2011-10-24 3 2011-10-24 4 2011-10-24 5 2011-10-24 6 2011-10-24 7 2011-10-24 8 2011-10-24 Name: obsdate, dtype: object
import numpy as np
from astropy.table import Table
a = [1, 4, 5]
b = [2.0, 5.0, 8.2]
c = ['x', 'y', 'z']
t = Table([a, b, c], names=('a', 'b', 'c'), meta={'name': 'first table'})
t
a | b | c |
---|---|---|
int64 | float64 | str1 |
1 | 2.0 | x |
4 | 5.0 | y |
5 | 8.2 | z |
data_rows = [(1, 2.0, 'x'),
(4, 5.0, 'y'),
(5, 8.2, 'z')]
t = Table(rows=data_rows, names=('a', 'b', 'c'), meta={'name': 'first table'},
dtype=('i4', 'f8', 'S1'))
t
a | b | c |
---|---|---|
int32 | float64 | bytes1 |
1 | 2.0 | x |
4 | 5.0 | y |
5 | 8.2 | z |
t['b'].unit = 's'
t
a | b | c |
---|---|---|
s | ||
int32 | float64 | bytes1 |
1 | 2.0 | x |
4 | 5.0 | y |
5 | 8.2 | z |
t['b'].format = '7.3f'
t
a | b | c |
---|---|---|
s | ||
int32 | float64 | bytes1 |
1 | 2.000 | x |
4 | 5.000 | y |
5 | 8.200 | z |
t.colnames
['a', 'b', 'c']
# 行索引
t[0:2]['b']
2.0 |
5.0 |
from astropy.time import Time
from astropy.coordinates import SkyCoord
tm = Time(['2000:002', '2002:345'])
sc = SkyCoord([10, 20], [-45, +40], unit='deg')
t = Table([tm, sc], names=['time', 'skycoord'])
t
time | skycoord |
---|---|
deg,deg | |
object | object |
2000:002:00:00:00.000 | 10.0,-45.0 |
2002:345:00:00:00.000 | 20.0,40.0 |
from astropy.table import Table, Column
t = Table()
t['a'] = [1, 4]
t['b'] = Column([2.0, 5.0], unit='cm', description='Velocity')
t['c'] = ['x', 'y']
t = Table(names=('a', 'b', 'c'), dtype=('f4', 'i4', 'S2'))
t.add_row((1, 2.0, 'x'))
t.add_row((4, 5.0, 'y'))
t
a | b | c |
---|---|---|
float32 | int32 | bytes2 |
1.0 | 2 | x |
4.0 | 5 | y |
# Column
col = Column([1, 2], name='a') # shape=(2,)
col = Column([[1, 2], [3, 4]], name='a') # shape=(2, 2)
col = Column([1, 2], name='a', dtype=float)
col = Column(np.array([1, 2]), name='a')
col = Column(['hello', 'world'], name='a')
t.columns # Dict of table columns (access by column name, index, or slice)
t.colnames # List of column names
t.meta # Dict of meta-data
len(t) # Number of table rows
3
# access
t['a'] # Column 'a'
t['a'][1] # Row 1 of column 'a'
t[1] # Row obj for with row 1 values
t[1]['a'] # Column 'a' of row 1
t[2:5] # Table object with rows 2:5
t[[1, 3, 4]] # Table object with rows 1, 3, 4 (copy)
t[np.array([1, 3, 4])] # Table object with rows 1, 3, 4 (copy)
t[[]] # Same table definition but with no rows of data
t['a', 'c'] # Table with cols 'a', 'c' (copy)
dat = np.array(t) # Copy table data to numpy structured array object
t['a'].quantity # an astropy.units.Quantity for Column 'a'
t['a'].to('km') # an astropy.units.Quantity for Column 'a' in units of kilometers
t.columns[1] # Column 1 (which is the 'b' column)
t.columns[0:2] # New table with columns 0 and 1
##
print(t) # Print formatted version of table to the screen
t.pprint() # Same as above
t.pprint(show_unit=True) # Show column unit
t.pprint(show_name=False) # Do not show column names
t.pprint(max_lines=-1, max_width=-1) # Print full table no matter how long / wide it is
t.more() # Interactively scroll through table like Unix "more"
print(t['a']) # Formatted column values
t['a'].pprint() # Same as above, with same options as Table.pprint()
t['a'].more() # Interactively scroll through column
lines = t.pformat() # Formatted table as a list of lines (same options as pprint)
lines = t['a'].pformat() # Formatted column values as a list
t['b'].format = "%6.3f"
t['b'].unit = 'm sec^-1'
t
a | b | c |
---|---|---|
m sec^-1 | ||
int64 | float64 | str1 |
1 | 2.000 | x |
4 | 5.000 | y |
5 | 8.200 | z |
t.info('stats')
<Table length=3> name mean std min max ---- ------------- ------------- --- --- a 3.33333333333 1.6996731712 1 5 b 5.06666666667 2.53157833947 2.0 8.2 c -- -- -- --
/Users/hebl/anaconda/lib/python3.5/site-packages/astropy/table/column.py:268: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison return self.data.__eq__(other)
t['b'].info
name = b dtype = float64 unit = m sec^-1 format = %6.3f class = Column n_bad = 0 length = 3
!head data/catalog
1 BD+44 4550 3 36042 46 000001.1+444022000509.9+451345114.44-16.88 6.70 +0.07 +0.08 A1Vn -0.012-0.018 -018 195 4.2 21.6AC 3 2 BD-01 4525 6128569 235956.2-010330000503.8-003011 98.33-61.14 6.29 +1.10 +1.02 gG9 +0.045-0.060 +014V 3 33 PscBD-06 6357 281285721002I Var? 000013.0-061601000520.1-054227 93.75-65.93 4.61 +1.04 +0.89 +0.54 K0IIIbCN-0.5 -0.009+0.089 +.014-006SB1O < 17 2.5 0.0 3* 4 86 PegBD+12 5063 87 917012004 000033.8+125023000542.0+132346106.19-47.98 5.51 +0.90 G5III +0.045-0.012 -002V? 5 BD+57 2865 123 21085 61 V640 Cas 000101.8+575245000616.0+582612117.03-03.92 5.96 +0.67 +0.20 G5V +0.263+0.030 +.047-012V 0.8 1.4 * 6 CD-4914337 142214963 W 000108.4-493751000619.0-490430321.61-66.38 5.70 +0.52 +0.05 G1IV +0.565-0.038 +.050+003SB 5.7 5.4 * 7 10 CasBD+63 2107 144 109782005 000114.4+633822000626.5+641146118.06 1.75 5.59 -0.03 -0.19 B9III e+0.008 0.000 -000V 153 * 8 BD+28 4704 166 73743 69 33 000125.2+282811000636.8+290117111.26-32.83 6.13 +0.75 +0.33 K0V +0.380-0.182 +.067-008V 2.6 158.6AB 4* 9 CD-23 4 2031660531003 000143.0-233947000650.1-230627 52.21-79.14 6.18 +0.38 +0.05 A7V +0.100-0.045 +003V 10 BD-18 6428 256147090 000211.8-175639000718.2-172311 74.36-75.90 6.19 +0.14 +0.10 A6Vn -0.018+0.036 -009V? 195 *
##IO
bsc = Table.read("data/catalog",
readme="http://vizier.china-vo.org/ftp/cats/V/50/ReadMe",
format="ascii.cds")
bsc
Downloading http://vizier.china-vo.org/ftp/cats/V/50/ReadMe [Done]
HR | Name | DM | HD | SAO | FK5 | IRflag | r_IRflag | Multiple | ADS | ADScomp | VarID | RAh1900 | RAm1900 | RAs1900 | DE-1900 | DEd1900 | DEm1900 | DEs1900 | RAh | RAm | RAs | DE- | DEd | DEm | DEs | GLON | GLAT | Vmag | n_Vmag | u_Vmag | B-V | u_B-V | U-B | u_U-B | R-I | n_R-I | SpType | n_SpType | pmRA | pmDE | n_Parallax | Parallax | RadVel | n_RadVel | l_RotVel | RotVel | u_RotVel | Dmag | Sep | MultID | MultCnt | NoteFlag |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
h | min | s | deg | arcmin | arcsec | h | min | s | deg | arcmin | arcsec | deg | deg | mag | mag | mag | mag | arcsec / yr | arcsec / yr | arcsec | km / s | km / s | mag | arcsec | ||||||||||||||||||||||||||||
int64 | str10 | str11 | int64 | int64 | int64 | str1 | str1 | str1 | str5 | str2 | str9 | int64 | int64 | float64 | str1 | int64 | int64 | int64 | int64 | int64 | float64 | str1 | int64 | int64 | int64 | float64 | float64 | float64 | str1 | str1 | float64 | str1 | float64 | str1 | float64 | str1 | str18 | str1 | float64 | float64 | str1 | float64 | int64 | str4 | str2 | int64 | str1 | float64 | float64 | str4 | int64 | str1 |
1 | -- | BD+44 4550 | 3 | 36042 | -- | -- | -- | -- | 46 | -- | -- | 0 | 0 | 1.1 | + | 44 | 40 | 22 | 0 | 5 | 9.9 | + | 45 | 13 | 45 | 114.44 | -16.88 | 6.7 | -- | -- | 0.07 | -- | 0.08 | -- | -- | -- | A1Vn | -- | -0.012 | -0.018 | -- | -- | -18 | -- | -- | 195 | -- | 4.2 | 21.6 | AC | 3 | -- |
2 | -- | BD-01 4525 | 6 | 128569 | -- | -- | -- | -- | -- | -- | -- | 23 | 59 | 56.2 | - | 1 | 3 | 30 | 0 | 5 | 3.8 | - | 0 | 30 | 11 | 98.33 | -61.14 | 6.29 | -- | -- | 1.1 | -- | 1.02 | -- | -- | -- | gG9 | -- | 0.045 | -0.06 | -- | -- | 14 | V | -- | -- | -- | -- | -- | -- | -- | -- |
3 | 33 Psc | BD-06 6357 | 28 | 128572 | 1002 | I | -- | -- | -- | -- | Var? | 0 | 0 | 13.0 | - | 6 | 16 | 1 | 0 | 5 | 20.1 | - | 5 | 42 | 27 | 93.75 | -65.93 | 4.61 | -- | -- | 1.04 | -- | 0.89 | -- | 0.54 | -- | K0IIIbCN-0.5 | -- | -0.009 | 0.089 | -- | 0.014 | -6 | SB1O | < | 17 | -- | 2.5 | 0.0 | -- | 3 | * |
4 | 86 Peg | BD+12 5063 | 87 | 91701 | 2004 | -- | -- | -- | -- | -- | -- | 0 | 0 | 33.8 | + | 12 | 50 | 23 | 0 | 5 | 42.0 | + | 13 | 23 | 46 | 106.19 | -47.98 | 5.51 | -- | -- | 0.9 | -- | -- | -- | -- | -- | G5III | -- | 0.045 | -0.012 | -- | -- | -2 | V? | -- | -- | -- | -- | -- | -- | -- | -- |
5 | -- | BD+57 2865 | 123 | 21085 | -- | -- | -- | -- | 61 | -- | V640 Cas | 0 | 1 | 1.8 | + | 57 | 52 | 45 | 0 | 6 | 16.0 | + | 58 | 26 | 12 | 117.03 | -3.92 | 5.96 | -- | -- | 0.67 | -- | 0.2 | -- | -- | -- | G5V | -- | 0.263 | 0.03 | -- | 0.047 | -12 | V | -- | -- | -- | 0.8 | 1.4 | -- | -- | * |
6 | -- | CD-4914337 | 142 | 214963 | -- | -- | -- | W | -- | -- | -- | 0 | 1 | 8.4 | - | 49 | 37 | 51 | 0 | 6 | 19.0 | - | 49 | 4 | 30 | 321.61 | -66.38 | 5.7 | -- | -- | 0.52 | -- | 0.05 | -- | -- | -- | G1IV | -- | 0.565 | -0.038 | -- | 0.05 | 3 | SB | -- | -- | -- | 5.7 | 5.4 | -- | -- | * |
7 | 10 Cas | BD+63 2107 | 144 | 10978 | 2005 | -- | -- | -- | -- | -- | -- | 0 | 1 | 14.4 | + | 63 | 38 | 22 | 0 | 6 | 26.5 | + | 64 | 11 | 46 | 118.06 | 1.75 | 5.59 | -- | -- | -0.03 | -- | -0.19 | -- | -- | -- | B9III | e | 0.008 | 0.0 | -- | -- | 0 | V | -- | 153 | -- | -- | -- | -- | -- | * |
8 | -- | BD+28 4704 | 166 | 73743 | -- | -- | -- | -- | 69 | -- | 33 | 0 | 1 | 25.2 | + | 28 | 28 | 11 | 0 | 6 | 36.8 | + | 29 | 1 | 17 | 111.26 | -32.83 | 6.13 | -- | -- | 0.75 | -- | 0.33 | -- | -- | -- | K0V | -- | 0.38 | -0.182 | -- | 0.067 | -8 | V | -- | -- | -- | 2.6 | 158.6 | AB | 4 | * |
9 | -- | CD-23 4 | 203 | 166053 | 1003 | -- | -- | -- | -- | -- | -- | 0 | 1 | 43.0 | - | 23 | 39 | 47 | 0 | 6 | 50.1 | - | 23 | 6 | 27 | 52.21 | -79.14 | 6.18 | -- | -- | 0.38 | -- | 0.05 | -- | -- | -- | A7V | -- | 0.1 | -0.045 | -- | -- | 3 | V | -- | -- | -- | -- | -- | -- | -- | -- |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
9101 | -- | BD-17 6868 | 225197 | 147064 | -- | -- | -- | -- | -- | -- | -- | 23 | 59 | 12.4 | - | 17 | 5 | 3 | 0 | 4 | 19.7 | - | 16 | 31 | 44 | 74.7 | -74.79 | 5.78 | -- | -- | 1.1 | -- | 1.05 | -- | -- | -- | K2III | -- | 0.039 | -0.059 | -- | -- | -27 | -- | -- | -- | -- | -- | -- | -- | -- | -- |
9102 | -- | CD-2918950 | 225200 | 166031 | -- | -- | -- | -- | -- | -- | -- | 23 | 59 | 13.2 | - | 29 | 49 | 33 | 0 | 4 | 20.3 | - | 29 | 16 | 7 | 18.53 | -79.41 | 6.4 | -- | -- | 0.0 | -- | -0.05 | -- | -- | -- | A0V | -- | 0.03 | 0.014 | -- | -- | 28 | -- | -- | -- | -- | -- | -- | -- | -- | -- |
9103 | 3 Cet | BD-11 6194 | 225212 | 147066 | 2001 | I | -- | -- | -- | -- | 13 | 23 | 59 | 23.0 | - | 11 | 3 | 58 | 0 | 4 | 30.1 | - | 10 | 30 | 34 | 87.07 | -70.04 | 4.94 | -- | -- | 1.63 | -- | 1.92 | -- | -- | -- | K3Ib | v | -0.005 | -0.011 | -- | 0.016 | -42 | V | < | 17 | -- | -- | -- | -- | -- | -- |
9104 | -- | BD+66 1679 | 225216 | 10956 | -- | -- | -- | -- | -- | -- | -- | 23 | 59 | 30.1 | + | 66 | 36 | 32 | 0 | 4 | 42.0 | + | 67 | 10 | 0 | 118.41 | 4.71 | 5.67 | -- | -- | 1.07 | -- | 0.93 | -- | -- | -- | K1III | -- | 0.092 | 0.03 | -- | 0.013 | -27 | -- | -- | -- | -- | -- | -- | -- | -- | -- |
9105 | -- | BD+41 4933 | 225218 | 36037 | -- | I | -- | -- | 30 | -- | -- | 23 | 59 | 28.2 | + | 41 | 32 | 10 | 0 | 4 | 36.7 | + | 42 | 5 | 32 | 113.72 | -19.94 | 6.01 | R | -- | -- | -- | -- | -- | -- | -- | B9III | -- | 0.005 | -0.022 | -- | -- | -8 | SB | -- | -- | -- | 3.7 | 5.4 | -- | -- | * |
9106 | -- | CP-73 2346 | 225233 | 255629 | -- | -- | -- | -- | -- | -- | -- | 23 | 59 | 26.8 | - | 73 | 27 | 12 | 0 | 4 | 30.7 | - | 72 | 53 | 52 | 307.68 | -43.8 | 7.31 | -- | -- | 0.44 | -- | 0.01 | -- | -- | -- | F2V | -- | 0.01 | -0.054 | -- | -- | 8 | -- | -- | -- | -- | -- | -- | -- | -- | -- |
9107 | -- | BD+33 4828 | 225239 | 53622 | 2002 | -- | -- | -- | -- | -- | -- | 23 | 59 | 39.2 | + | 34 | 6 | 2 | 0 | 4 | 53.8 | + | 34 | 39 | 35 | 112.17 | -27.24 | 6.12 | -- | -- | 0.62 | -- | 0.09 | -- | -- | -- | G2V | -- | 0.772 | 0.089 | -- | 0.035 | 4 | V | -- | -- | -- | -- | -- | -- | -- | -- |
9108 | -- | CP-72 2800 | 225253 | 255631 | 1001 | -- | -- | -- | -- | -- | -- | 23 | 59 | 37.0 | - | 71 | 59 | 36 | 0 | 4 | 41.3 | - | 71 | 26 | 13 | 308.18 | -45.21 | 5.59 | -- | -- | -0.12 | -- | -0.42 | -- | -- | -- | B8IV-V | -- | 0.028 | -0.014 | -- | -- | -3 | V | -- | -- | -- | -- | -- | -- | -- | -- |
9109 | -- | BD+25 5068 | 225276 | 73731 | -- | I | -- | -- | 42 | -- | -- | 23 | 59 | 47.1 | + | 26 | 5 | 33 | 0 | 4 | 56.0 | + | 26 | 38 | 56 | 110.22 | -35.07 | 6.25 | -- | -- | 1.4 | -- | 1.59 | -- | -- | -- | K4IIIb | -- | 0.11 | -0.012 | -- | -- | -5 | -- | -- | -- | -- | 4.5 | 17.5 | -- | -- | -- |
9110 | -- | BD+60 2667 | 225289 | 10962 | -- | -- | -- | -- | -- | -- | V567 Cas | 23 | 59 | 55.9 | + | 60 | 45 | 26 | 0 | 5 | 6.2 | + | 61 | 18 | 51 | 117.4 | -1.06 | 5.8 | -- | -- | -0.09 | -- | -0.32 | -- | -- | -- | B8IVpHgMn | -- | 0.015 | 0.005 | -- | -- | 14 | V | -- | 50 | -- | -- | -- | -- | -- | * |
Format | Read | Write | Auto-identify | Deprecated |
---|---|---|---|---|
aastex | Yes | Yes | No | Yes |
ascii | Yes | Yes | No | |
ascii.aastex | Yes | Yes | No | |
ascii.basic | Yes | Yes | No | |
ascii.cds | Yes | No | No | |
ascii.commented_header | Yes | Yes | No | |
ascii.daophot | Yes | No | No | |
ascii.ecsv | Yes | Yes | No | |
ascii.fixed_width | Yes | Yes | No | |
ascii.fixed_width_no_header | Yes | Yes | No | |
ascii.fixed_width_two_line | Yes | Yes | No | |
ascii.html | Yes | Yes | Yes | |
ascii.ipac | Yes | Yes | No | |
ascii.latex | Yes | Yes | Yes | |
ascii.no_header | Yes | Yes | No | |
ascii.rdb | Yes | Yes | Yes | |
ascii.sextractor | Yes | No | No | |
ascii.tab | Yes | Yes | No | |
ascii.csv | Yes | Yes | Yes | |
cds | Yes | No | No | Yes |
daophot | Yes | No | No | Yes |
fits | Yes | Yes | Yes | |
hdf5 | Yes | Yes | Yes | |
html | Yes | Yes | No | Yes |
ipac | Yes | Yes | No | Yes |
latex | Yes | Yes | No | Yes |
rdb | Yes | Yes | No | Yes |
votable | Yes | Yes | Yes |
t = Table.read('aj285677t3_votable.xml')