Reputation: 168
I am working with this ASCII Dataset wherein I need to remove certain rows. I am using ASTROPY:
from astropy.io import ascii
gw170817 = ascii.read('gw170817_afterglow_data_full.txt')
Table length=215
DateUT T Telescope Freq FluxD FluxDErr
str24 float64 str10 float64 str7 float64
2017-Aug-18.10 0.57 VLA 9700000000.0 <144 --
2017-Aug-18.1 0.6 Swift 2.41e+17 <7.8e-3 --
2017-Aug-18.21 0.68 ATCA 8500000000.0 <120 --
2017-Aug-18.21 0.68 ATCA 10500000000.0 <150 --
2017-Aug-18.2 0.7 NuSTAR 1.2e+18 <7.3e-4 --
2017-Aug-18.46 0.93 uGMRT 610000000.0 <195 --
2017-Aug-18.5 1.0 Swift 2.41e+17 <7.5e-2 --
2017-Aug-18.6 1.1 Swift 2.41e+17 <5.0e-3 --
2017-Aug-18.95 1.43 ALMA 339000000000.0 <126 --
2017-Aug-18.97 1.44 VLA 10000000000.0 <13.8 --
... ... ... ... ... ...
2019-Sep-21--27 767.0 VLA 3000000000.0 4.90e0 1.8
2020-Mar-13 938.0 Chandra 2.41e+17 1.30e-4 5.23e-05
2020-Nov-14 1185.0 ATCA 2100000000.0 <51 --
2021-Feb-20 1283.0 ATCA 2100000000.0 <75 --
2021-Apr-06 1328.0 ATCA 2100000000.0 <54 --
2021-Apr-08 1330.0 ATCA 5500000000.0 <44 --
2021-Apr-08 1330.0 ATCA 9000000000.0 <31 --
2020-Dec-09--2021-Jan-27 1231.0 Chandra 2.41e+17 1.70e-4 4.7e-05
2020-Sep-19--2021-Feb-08 1228.0 VLA 3000000000.0 2.86e0 0.99
2020-Feb-10 1273.0 VLA 15000000000.0 <5.7 --
I want to keep only rows that satisfy gw170817['Freq']==3000000000 and gw170817['Telescope']=='VLA'. Please help me out.
Upvotes: 0
Views: 103
Reputation: 124
With an astropy.table.table.Table
object, you can generate a mask object (see their doc here):
(gw170817['Freq']==3000000000) & (gw170817['Telescope']=='VLA')
and then apply it to your initial table to get what you want:
gw170817[(gw170817['Freq']==3000000000) & (gw170817['Telescope']=='VLA')]
Upvotes: 0