Skip to content

Is there a way to cast a column to float that handle no numeric values? #3195

Discussion options

You must be logged in to vote

What about just using casting?

>>> from datatable import dt
>>> DT = dt.Frame(['apple', '1.0', '2', -3, None]/dt.str32)
>>> DT
   | C0   
   | str32
-- + -----
 0 | apple
 1 | 1.0  
 2 | 2    
 3 | -3   
 4 | NA   
[5 rows x 1 column]
>>> DT[0] = dt.float32
>>> DT
   |      C0
   | float32
-- + -------
 0 |      NA
 1 |       1
 2 |       2
 3 |      -3
 4 |      NA
[5 rows x 1 column]

In the general case, one can use .as_type().

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by argenisleon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants