datatable.stype.__call__()¶
Cast column col into the new stype.
An stype can be used as a function that converts columns into that
specific stype. In the same way as you could write int(3.14) in
Python to convert a float value into integer, you can likewise
write dt.int32(f.A) to convert column A into stype int32.
Parameters¶
col
FExprA single- or multi- column expression. All columns will be converted into the desired stype.
return
FExprExpression that converts its inputs into the current stype.
Examples¶
from datatable import dt, f
df = dt.Frame({'A': ['1', '1', '2', '1', '2'],
'B': [None, '2', '3', '4', '5'],
'C': [1, 2, 1, 1, 2]})
df
| A | B | C | ||
|---|---|---|---|---|
| str32 | str32 | int32 | ||
| 0 | 1 | NA | 1 | |
| 1 | 1 | 2 | 2 | |
| 2 | 2 | 3 | 1 | |
| 3 | 1 | 4 | 1 | |
| 4 | 2 | 5 | 2 |
Convert column A from string stype to integer stype:
df[:, dt.int32(f.A)]
| A | ||
|---|---|---|
| int32 | ||
| 0 | 1 | |
| 1 | 1 | |
| 2 | 2 | |
| 3 | 1 | |
| 4 | 2 |
Convert multiple columns to different stypes:
df[:, [dt.int32(f.A), dt.str32(f.C)]]
| A | C | ||
|---|---|---|---|
| int32 | str32 | ||
| 0 | 1 | 1 | |
| 1 | 1 | 2 | |
| 2 | 2 | 1 | |
| 3 | 1 | 1 | |
| 4 | 2 | 2 |
See Also¶
dt.as_type()– equivalent method of casting a column intoanother stype.
The content on this page is licensed under the Creative Commons Attribution 4.0 License
(CC BY 4.0) ,
and code samples are licensed under the MIT License.