This is my code where this_proteinDF.loc[:, 'p-value']
contains masked values:
this_proteinDF.loc[:, 'p-value'] = this_proteinDF.loc[:, 'p-value'].apply(lambda x: np.nan if x is np.ma.masked else x)
This should change every masked value into np.nan
, however when I call the values after this operation it returns a float64 0.0
instead of nan
.
What's going on here and how do i fix this?
It seems you have several points of mis-understanding (you and me).
np.ma.masked
is a numpy
constant that supposed to mean that something is masked. I do not think it means what you think it means. 'p-value'
series masked. I'm thinking it's beneficial to you and maybe others to show the following.
mask
method
use pandas
to mask the things you'd like
df = pd.DataFrame({'p-value': [.001, .01, .1, .2, .05, .5]})
df
Check what's not significant
df['p-value'].gt(.05)
0 False
1 False
2 True
3 True
4 False
5 True
Name: p-value, dtype: bool
mask
will make True
values into np.nan
values
df.loc[:, 'is_sig'] = df['p-value'].mask(df['p-value'].gt(.05))
df
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.