diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000000..e69de29bb2 diff --git a/404.html b/404.html new file mode 100644 index 0000000000..a19e4c5dae --- /dev/null +++ b/404.html @@ -0,0 +1,642 @@ + + + +
+ + + + + + + + + + + + + + +narwhals.DataFrame
shape: tuple[int, int]
+
+
+ property
+
+
+schema: dict[str, DType]
+
+
+ property
+
+
+Get a dict[column name, DataType].
+ + + +Examples:
+>>> import polars as pl
+>>> import narwhals as nw
+>>> df_pl = pl.DataFrame(
+... {
+... "foo": [1, 2, 3],
+... "bar": [6.0, 7.0, 8.0],
+... "ham": ["a", "b", "c"],
+... }
+... )
+>>> df = nw.DataFrame(df_pl)
+>>> df.schema
+OrderedDict({'foo': Int64, 'bar': Float64, 'ham': String})
+```
+
columns: list[str]
+
+
+ property
+
+
+Get column names.
+ + + +Examples:
+Get column names.
+>>> import polars as pl
+>>> import narwhals as nw
+>>> df_pl = pl.DataFrame(
+... {
+... "foo": [1, 2, 3],
+... "bar": [6, 7, 8],
+... "ham": ["a", "b", "c"],
+... }
+... )
+>>> df = nw.DataFrame(df_pl)
+>>> df.columns
+['foo', 'bar', 'ham']
+
to_pandas()
+
+to_numpy()
+
+__getitem__(col_name)
+
+to_dict(*, as_series=True)
+
+with_columns(*exprs, **named_exprs)
+
+Add columns to this DataFrame.
+Added columns will replace existing columns with the same name.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
*exprs |
+
+ IntoExpr | Iterable[IntoExpr]
+ |
+
+
+
+ Column(s) to add, specified as positional arguments. + Accepts expression input. Strings are parsed as column names, other + non-expression inputs are parsed as literals. + |
+
+ ()
+ |
+
**named_exprs |
+
+ IntoExpr
+ |
+
+
+
+ Additional columns to add, specified as keyword arguments. + The columns will be renamed to the keyword used. + |
+
+ {}
+ |
+
Returns:
+Name | Type | +Description | +
---|---|---|
DataFrame |
+ Self
+ |
+
+
+
+ A new DataFrame with the columns added. + |
+
Creating a new DataFrame using this method does not create a new copy of +existing data.
+Examples:
+Pass an expression to add it as a new column.
+>>> import polars as pl
+>>> import narwhals as nw
+>>> df_pl = pl.DataFrame(
+... {
+... "a": [1, 2, 3, 4],
+... "b": [0.5, 4, 10, 13],
+... "c": [True, True, False, True],
+... }
+... )
+>>> df = nw.DataFrame(df_pl)
+>>> dframe = df.with_columns((nw.col("a") * 2).alias("a*2"))
+>>> dframe
+┌─────────────────────────────────────────────────┐
+| Narwhals DataFrame |
+| Use `narwhals.to_native()` to see native output |
+└─────────────────────────────────────────────────┘
+
>>> nw.to_native(dframe)
+shape: (4, 4)
+┌─────┬──────┬───────┬─────┐
+│ a ┆ b ┆ c ┆ a*2 │
+│ --- ┆ --- ┆ --- ┆ --- │
+│ i64 ┆ f64 ┆ bool ┆ i64 │
+╞═════╪══════╪═══════╪═════╡
+│ 1 ┆ 0.5 ┆ true ┆ 2 │
+│ 2 ┆ 4.0 ┆ true ┆ 4 │
+│ 3 ┆ 10.0 ┆ false ┆ 6 │
+│ 4 ┆ 13.0 ┆ true ┆ 8 │
+└─────┴──────┴───────┴─────┘
+
select(*exprs, **named_exprs)
+
+Select columns from this DataFrame.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
*exprs |
+
+ IntoExpr | Iterable[IntoExpr]
+ |
+
+
+
+ Column(s) to select, specified as positional arguments. + Accepts expression input. Strings are parsed as column names, + other non-expression inputs are parsed as literals. + |
+
+ ()
+ |
+
**named_exprs |
+
+ IntoExpr
+ |
+
+
+
+ Additional columns to select, specified as keyword arguments. + The columns will be renamed to the keyword used. + |
+
+ {}
+ |
+
Examples:
+Pass the name of a column to select that column.
+>>> import polars as pl
+>>> import narwhals as nw
+>>> df_pl = pl.DataFrame(
+... {
+... "foo": [1, 2, 3],
+... "bar": [6, 7, 8],
+... "ham": ["a", "b", "c"],
+... }
+... )
+>>> df = nw.DataFrame(df_pl)
+>>> dframe = df.select("foo")
+>>> dframe
+┌─────────────────────────────────────────────────┐
+| Narwhals DataFrame |
+| Use `narwhals.to_native()` to see native output |
+└─────────────────────────────────────────────────┘
+>>> nw.to_native(dframe)
+shape: (3, 1)
+┌─────┐
+│ foo │
+│ --- │
+│ i64 │
+╞═════╡
+│ 1 │
+│ 2 │
+│ 3 │
+└─────┘
+
Multiple columns can be selected by passing a list of column names.
+>>> dframe = df.select(["foo", "bar"])
+>>> dframe
+┌─────────────────────────────────────────────────┐
+| Narwhals DataFrame |
+| Use `narwhals.to_native()` to see native output |
+└─────────────────────────────────────────────────┘
+>>> nw.to_native(dframe)
+shape: (3, 2)
+┌─────┬─────┐
+│ foo ┆ bar │
+│ --- ┆ --- │
+│ i64 ┆ i64 │
+╞═════╪═════╡
+│ 1 ┆ 6 │
+│ 2 ┆ 7 │
+│ 3 ┆ 8 │
+└─────┴─────┘
+
Multiple columns can also be selected using positional arguments instead of a +list. Expressions are also accepted.
+>>> dframe = df.select(nw.col("foo"), nw.col("bar") + 1)
+>>> dframe
+┌─────────────────────────────────────────────────┐
+| Narwhals DataFrame |
+| Use `narwhals.to_native()` to see native output |
+└─────────────────────────────────────────────────┘
+>>> nw.to_native(dframe)
+shape: (3, 2)
+┌─────┬─────┐
+│ foo ┆ bar │
+│ --- ┆ --- │
+│ i64 ┆ i64 │
+╞═════╪═════╡
+│ 1 ┆ 7 │
+│ 2 ┆ 8 │
+│ 3 ┆ 9 │
+└─────┴─────┘
+
Use keyword arguments to easily name your expression inputs.
+>>> dframe = df.select(threshold=nw.col('foo')*2)
+>>> dframe
+┌─────────────────────────────────────────────────┐
+| Narwhals DataFrame |
+| Use `narwhals.to_native()` to see native output |
+└─────────────────────────────────────────────────┘
+>>> nw.to_native(dframe)
+shape: (3, 1)
+┌───────────┐
+│ threshold │
+│ --- │
+│ i64 │
+╞═══════════╡
+│ 2 │
+│ 4 │
+│ 6 │
+└───────────┘
+
rename(mapping)
+
+Rename column names.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
mapping |
+
+ dict[str, str]
+ |
+
+
+
+ Key value pairs that map from old name to new name, or a function + that takes the old name as input and returns the new name. + |
+ + required + | +
Examples:
+>>> import polars as pl
+>>> import narwhals as nw
+>>> df_pl = pl.DataFrame(
+... {"foo": [1, 2, 3], "bar": [6, 7, 8], "ham": ["a", "b", "c"]}
+... )
+>>> df = nw.DataFrame(df_pl)
+>>> dframe = df.rename({"foo": "apple"})
+>>> dframe
+┌─────────────────────────────────────────────────┐
+| Narwhals DataFrame |
+| Use `narwhals.to_native()` to see native output |
+└─────────────────────────────────────────────────┘
+
>>> nw.to_native(dframe)
+shape: (3, 3)
+┌───────┬─────┬─────┐
+│ apple ┆ bar ┆ ham │
+│ --- ┆ --- ┆ --- │
+│ i64 ┆ i64 ┆ str │
+╞═══════╪═════╪═════╡
+│ 1 ┆ 6 ┆ a │
+│ 2 ┆ 7 ┆ b │
+│ 3 ┆ 8 ┆ c │
+└───────┴─────┴─────┘
+>>> dframe = df.rename(lambda column_name: "f" + column_name[1:])
+>>> dframe
+┌─────────────────────────────────────────────────┐
+| Narwhals DataFrame |
+| Use `narwhals.to_native()` to see native output |
+└─────────────────────────────────────────────────┘
+>>> nw.to_native(dframe)
+shape: (3, 3)
+┌─────┬─────┬─────┐
+│ foo ┆ far ┆ fam │
+│ --- ┆ --- ┆ --- │
+│ i64 ┆ i64 ┆ str │
+╞═════╪═════╪═════╡
+│ 1 ┆ 6 ┆ a │
+│ 2 ┆ 7 ┆ b │
+│ 3 ┆ 8 ┆ c │
+└─────┴─────┴─────┘
+
head(n)
+
+drop(*columns)
+
+unique(subset)
+
+filter(*predicates)
+
+group_by(*keys)
+
+sort(by, *more_by, descending=False)
+
+join(other, *, how='inner', left_on, right_on)
+
+narwhals.Expr
str: ExprStringNamespace
+
+
+ property
+
+
+alias(name)
+
+cast(dtype)
+
+mean()
+
+sum()
+
+min()
+
+max()
+
+n_unique()
+
+unique()
+
+is_between(lower_bound, upper_bound, closed='both')
+
+is_in(other)
+
+is_null()
+
+drop_nulls()
+
+sample(n=None, fraction=None, *, with_replacement=False)
+
+narwhals.LazyFrame
schema: dict[str, DType]
+
+
+ property
+
+
+columns: list[str]
+
+
+ property
+
+
+with_columns(*exprs, **named_exprs)
+
+select(*exprs, **named_exprs)
+
+rename(mapping)
+
+head(n)
+
+drop(*columns)
+
+unique(subset)
+
+filter(*predicates)
+
+group_by(*keys)
+
+sort(by, *more_by, descending=False)
+
+join(other, *, how='inner', left_on, right_on)
+
+collect()
+
+narwhals
Here are the top-level functions available in Narwhals.
+ + +from_native(native_dataframe)
+
+Convert dataframe to Narwhals DataFrame or LazyFrame.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
native_dataframe |
+
+ Any
+ |
+
+
+
+ Raw dataframe from user. +Input object can be: +
|
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ DataFrame | LazyFrame
+ |
+
+
+
+ narwhals.DataFrame or narwhals.LazyFrame + |
+
to_native(narwhals_object)
+
+Convert Narwhals object to native one.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
narwhals_object |
+
+ LazyFrame | DataFrame | Series
+ |
+
+
+
+ Narwhals object. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Any
+ |
+
+
+
+ Object of class that user started with. + |
+
col(*names)
+
+Instantiate an expression, similar to polars.col
.
min(*columns)
+
+Instantiate an expression representing the minimum of one or more columns, similar to polars.min
.
max(*columns)
+
+Instantiate an expression representing the maximum of one or more columns, similar to polars.max
.
mean(*columns)
+
+Instantiate an expression representing the mean of one or more columns, similar to polars.mean
.
sum(*columns)
+
+Instantiate an expression representing the sum of one or more columns, similar to polars.sum
.
len()
+
+Instantiate an expression representing the length of a dataframe, similar to polars.len
.
sum_horizontal(*exprs)
+
+Instantiate an expression representing the horizontal sum of one or more expressions, similar to polars.sum_horizontal
.
narwhals.Series
name: str
+
+
+ property
+
+
+dtype: Any
+
+
+ property
+
+
+shape: tuple[int]
+
+
+ property
+
+
+alias(name)
+
+rename(name)
+
+cast(dtype)
+
+item()
+
+is_between(lower_bound, upper_bound, closed='both')
+
+is_in(other)
+
+is_null()
+
+drop_nulls()
+
+n_unique()
+
+unique()
+
+zip_with(mask, other)
+
+sample(n=None, fraction=None, *, with_replacement=False)
+
+to_numpy()
+
+to_pandas()
+
+mean()
+
+std()
+
+{"use strict";/*!
+ * escape-html
+ * Copyright(c) 2012-2013 TJ Holowaychuk
+ * Copyright(c) 2015 Andreas Lubbe
+ * Copyright(c) 2015 Tiancheng "Timothy" Gu
+ * MIT Licensed
+ */var Va=/["'&<>]/;qn.exports=za;function za(e){var t=""+e,r=Va.exec(t);if(!r)return t;var o,n="",i=0,s=0;for(i=r.index;i