You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To convert the values of a column to another type, user can use the following syntax:
375
+
376
+
`modify!(ds, col => byrow(T))`
377
+
378
+
where `ds` is the input data set, `col` is the column which its values' type is going to be converted and `T` is the new type (the `byrow` function is discussed in [Row-wise operations](https://sl-solution.github.io/InMemoryDatasets.jl/stable/man/byrow/), and the `modify!` function is discussed in [Transforming datasets](https://sl-solution.github.io/InMemoryDatasets.jl/stable/man/modify/#Transforming-data-sets)). This functionality must be used in cases where each individual value needed to be converted. For scenarios that the convertion process needs the information of all values in a column, the `byrow` function must be dropped, e.g. `modify!(ds, col => PooledArray)`. Additionally, user may allow `Julia` to find the most suitable type of a column by calling `modify!(ds, col => byrow(identity))`. In the following example we are using `modify!` to correct the type of columns in `ds`.
379
+
380
+
> Note that in the following example calling `byrow(identity)` on `:y` convert type `Any` to `Integer`. However, note that `Integer` is an abstract type and it will slow down the performance of operations on `ds`. To improve the performance of calculations, user may use `modify!(ds, :y => byrow(Int))` instead.
381
+
382
+
```jldoctest
383
+
julia> using PooledArrays
384
+
385
+
julia> ds = Dataset(x = [missing,2,3,4], y = Any[1,missing,-1,true], z = ["a", "bc", "a", missing])
The following functions are very handy when working with a data set, for more information look at the package documentation. Note that functions which end with `!` modify the original data set.
Copy file name to clipboardExpand all lines: src/byrow/doc.jl
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -98,6 +98,8 @@ byrow_docs_text = """
98
98
Perform a row-wise operation specified by `fun` on selected columns `cols`. Generally,
99
99
`fun` can be any function that returns a scalar value for each row.
100
100
101
+
> User can pass a type as `fun` when `cols` is referring to a single column. In this case, `byrow` simply converts the selected column to vector of type `fun`.
102
+
101
103
`byrow` is fine tuned for the following operations. To get extra help for each of them search help for `byrow(fun)`, e.g. `?byrow(sum)`;
102
104
103
105
# Reduction operations
@@ -1234,6 +1236,8 @@ Variant of `byrow(stdze!)` which pass a copy of `ds` and leave `ds` untouched.
1234
1236
1235
1237
Return the result of calling `fun` on each row of `ds` selected by `cols`. The `fun` function must accept one argument which contains the values of each row as a vector of values and return a scalar.
1236
1238
1239
+
When user passes a type as `fun` and a single column as `cols`, `byrow` convert the corresponding column to the type specified by `fun`.
1240
+
1237
1241
For generic functions there are two special cases:
1238
1242
1239
1243
* When `cols` is a single column, `byrow(ds, fun, cols)` acts like `fun.(ds[:, cols])`
0 commit comments