Skip to content Skip to sidebar Skip to footer

Replacing Masked Values (--) With A Null Or None Value Using Fiil_value From Ma Numpy In Python

Is there a way to replace a masked value in a numpy masked array as a null or None value? This is what I have tried but does not work. for stars in range(length_masterlist_final):

Solution 1:

Use Astropy:

>>>from pandas import DataFrame>>>from astropy.table import Table>>>import numpy as np>>>>>>df = DataFrame()>>>df['a'] = [1, np.nan, 2]>>>df['b'] = [3, 4, np.nan]>>>df
    a   b
0   1   3
1 NaN   4
2   2 NaN
>>>t = Table.from_pandas(df)>>>t
<Table masked=True length=3>
   a       b   
float64 float64
------- -------
    1.0     3.0
     --     4.0
    2.0      --
>>>t.write('photometry.csv', format='ascii.csv')>>> 
(astropy)neptune$ cat photometry.csv 
a,b
1.0,3.0
,4.0
2.0,

You can specify arbitrary transformations from table values to output values using the fill_values parameter (http://docs.astropy.org/en/stable/io/ascii/write.html#parameters-for-write).

Post a Comment for "Replacing Masked Values (--) With A Null Or None Value Using Fiil_value From Ma Numpy In Python"