lib/polars/data_frame.rb in polars-df-0.1.3 vs lib/polars/data_frame.rb in polars-df-0.1.4
- old
+ new
@@ -878,11 +878,11 @@
# {
# "key" => ["a", "b", "c"],
# "val" => [1, 2, 3]
# }
# )
- # df.reverse()
+ # df.reverse
# # =>
# # shape: (3, 2)
# # ┌─────┬─────┐
# # │ key ┆ val │
# # │ --- ┆ --- │
@@ -1996,12 +1996,109 @@
# # ]
def get_column(name)
self[name]
end
- # def fill_null
- # end
+ # Fill null values using the specified value or strategy.
+ #
+ # @param value [Numeric]
+ # Value used to fill null values.
+ # @param strategy [nil, "forward", "backward", "min", "max", "mean", "zero", "one"]
+ # Strategy used to fill null values.
+ # @param limit [Integer]
+ # Number of consecutive null values to fill when using the 'forward' or
+ # 'backward' strategy.
+ # @param matches_supertype [Boolean]
+ # Fill all matching supertype of the fill `value`.
+ #
+ # @return [DataFrame]
+ #
+ # @example
+ # df = Polars::DataFrame.new(
+ # {
+ # "a" => [1, 2, nil, 4],
+ # "b" => [0.5, 4, nil, 13]
+ # }
+ # )
+ # df.fill_null(99)
+ # # =>
+ # # shape: (4, 2)
+ # # ┌─────┬──────┐
+ # # │ a ┆ b │
+ # # │ --- ┆ --- │
+ # # │ i64 ┆ f64 │
+ # # ╞═════╪══════╡
+ # # │ 1 ┆ 0.5 │
+ # # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
+ # # │ 2 ┆ 4.0 │
+ # # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
+ # # │ 99 ┆ 99.0 │
+ # # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
+ # # │ 4 ┆ 13.0 │
+ # # └─────┴──────┘
+ #
+ # @example
+ # df.fill_null(strategy: "forward")
+ # # =>
+ # # shape: (4, 2)
+ # # ┌─────┬──────┐
+ # # │ a ┆ b │
+ # # │ --- ┆ --- │
+ # # │ i64 ┆ f64 │
+ # # ╞═════╪══════╡
+ # # │ 1 ┆ 0.5 │
+ # # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
+ # # │ 2 ┆ 4.0 │
+ # # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
+ # # │ 2 ┆ 4.0 │
+ # # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
+ # # │ 4 ┆ 13.0 │
+ # # └─────┴──────┘
+ #
+ # @example
+ # df.fill_null(strategy: "max")
+ # # =>
+ # # shape: (4, 2)
+ # # ┌─────┬──────┐
+ # # │ a ┆ b │
+ # # │ --- ┆ --- │
+ # # │ i64 ┆ f64 │
+ # # ╞═════╪══════╡
+ # # │ 1 ┆ 0.5 │
+ # # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
+ # # │ 2 ┆ 4.0 │
+ # # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
+ # # │ 4 ┆ 13.0 │
+ # # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
+ # # │ 4 ┆ 13.0 │
+ # # └─────┴──────┘
+ #
+ # @example
+ # df.fill_null(strategy: "zero")
+ # # =>
+ # # shape: (4, 2)
+ # # ┌─────┬──────┐
+ # # │ a ┆ b │
+ # # │ --- ┆ --- │
+ # # │ i64 ┆ f64 │
+ # # ╞═════╪══════╡
+ # # │ 1 ┆ 0.5 │
+ # # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
+ # # │ 2 ┆ 4.0 │
+ # # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
+ # # │ 0 ┆ 0.0 │
+ # # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
+ # # │ 4 ┆ 13.0 │
+ # # └─────┴──────┘
+ def fill_null(value = nil, strategy: nil, limit: nil, matches_supertype: true)
+ _from_rbdf(
+ lazy
+ .fill_null(value, strategy: strategy, limit: limit, matches_supertype: matches_supertype)
+ .collect(no_optimization: true)
+ ._df
+ )
+ end
# Fill floating point NaN values by an Expression evaluation.
#
# @param fill_value [Object]
# Value to fill NaN with.
@@ -2355,10 +2452,10 @@
# )
# df.with_columns(
# [
# (Polars.col("a") ** 2).alias("a^2"),
# (Polars.col("b") / 2).alias("b/2"),
- # (Polars.col("c").is_not()).alias("not c")
+ # (Polars.col("c").is_not).alias("not c")
# ]
# )
# # =>
# # shape: (4, 6)
# # ┌─────┬──────┬───────┬──────┬──────┬───────┐