@@ -1100,6 +1100,9 @@ def row(self, index: int) -> tuple[Any, ...]:
1100
1100
Arguments:
1101
1101
index: Row number.
1102
1102
1103
+ Returns:
1104
+ A tuple of the values in the selected row.
1105
+
1103
1106
Notes:
1104
1107
cuDF doesn't support this method.
1105
1108
@@ -1133,6 +1136,14 @@ def row(self, index: int) -> tuple[Any, ...]:
1133
1136
def pipe (self , function : Callable [[Any ], Self ], * args : Any , ** kwargs : Any ) -> Self :
1134
1137
"""Pipe function call.
1135
1138
1139
+ Arguments:
1140
+ function: Function to apply.
1141
+ args: Positional arguments to pass to function.
1142
+ kwargs: Keyword arguments to pass to function.
1143
+
1144
+ Returns:
1145
+ The original object with the function applied.
1146
+
1136
1147
Examples:
1137
1148
>>> import polars as pl
1138
1149
>>> import pandas as pd
@@ -1175,12 +1186,15 @@ def pipe(self, function: Callable[[Any], Self], *args: Any, **kwargs: Any) -> Se
1175
1186
return super ().pipe (function , * args , ** kwargs )
1176
1187
1177
1188
def drop_nulls (self : Self , subset : str | list [str ] | None = None ) -> Self :
1178
- """Drop null values.
1189
+ """Drop rows that contain null values.
1179
1190
1180
1191
Arguments:
1181
1192
subset: Column name(s) for which null values are considered. If set to None
1182
1193
(default), use all columns.
1183
1194
1195
+ Returns:
1196
+ The original object with the rows removed that contained the null values.
1197
+
1184
1198
Notes:
1185
1199
pandas and Polars handle null values differently. Polars distinguishes
1186
1200
between NaN and Null, whereas pandas doesn't.
@@ -1221,6 +1235,12 @@ def drop_nulls(self: Self, subset: str | list[str] | None = None) -> Self:
1221
1235
def with_row_index (self , name : str = "index" ) -> Self :
1222
1236
"""Insert column which enumerates rows.
1223
1237
1238
+ Arguments:
1239
+ name: The name of the column as a string. The default is "index".
1240
+
1241
+ Returns:
1242
+ The original object with the column added.
1243
+
1224
1244
Examples:
1225
1245
Construct pandas as polars DataFrames:
1226
1246
@@ -1264,6 +1284,9 @@ def with_row_index(self, name: str = "index") -> Self:
1264
1284
def schema (self ) -> Schema :
1265
1285
r"""Get an ordered mapping of column names to their data type.
1266
1286
1287
+ Returns:
1288
+ A Narwhals Schema object that displays the mapping of column names.
1289
+
1267
1290
Examples:
1268
1291
>>> import polars as pl
1269
1292
>>> import pandas as pd
@@ -1300,6 +1323,9 @@ def schema(self) -> Schema:
1300
1323
def collect_schema (self : Self ) -> Schema :
1301
1324
r"""Get an ordered mapping of column names to their data type.
1302
1325
1326
+ Returns:
1327
+ A Narwhals Schema object that displays the mapping of column names.
1328
+
1303
1329
Examples:
1304
1330
>>> import polars as pl
1305
1331
>>> import pandas as pd
@@ -1337,6 +1363,9 @@ def collect_schema(self: Self) -> Schema:
1337
1363
def columns (self ) -> list [str ]:
1338
1364
"""Get column names.
1339
1365
1366
+ Returns:
1367
+ The column names stored in a list.
1368
+
1340
1369
Examples:
1341
1370
>>> import pandas as pd
1342
1371
>>> import polars as pl
@@ -1397,6 +1426,9 @@ def rows(
1397
1426
in the same order as the frame columns. Setting named=True will
1398
1427
return rows of dictionaries instead.
1399
1428
1429
+ Returns:
1430
+ The data as a list of rows.
1431
+
1400
1432
Examples:
1401
1433
>>> import pandas as pd
1402
1434
>>> import polars as pl
@@ -1452,6 +1484,9 @@ def iter_rows(
1452
1484
internally while iterating over the data.
1453
1485
See https://docs.pola.rs/api/python/stable/reference/dataframe/api/polars.DataFrame.iter_rows.html
1454
1486
1487
+ Returns:
1488
+ An iterator over the DataFrame of rows.
1489
+
1455
1490
Notes:
1456
1491
cuDF doesn't support this method.
1457
1492
@@ -1561,6 +1596,9 @@ def select(
1561
1596
**named_exprs: Additional columns to select, specified as keyword arguments.
1562
1597
The columns will be renamed to the keyword used.
1563
1598
1599
+ Returns:
1600
+ The dataframe containing only the selected columns.
1601
+
1564
1602
Examples:
1565
1603
>>> import pandas as pd
1566
1604
>>> import polars as pl
@@ -1674,6 +1712,9 @@ def rename(self, mapping: dict[str, str]) -> Self:
1674
1712
Arguments:
1675
1713
mapping: Key value pairs that map from old name to new name.
1676
1714
1715
+ Returns:
1716
+ The dataframe with the specified columns renamed.
1717
+
1677
1718
Examples:
1678
1719
>>> import pandas as pd
1679
1720
>>> import polars as pl
@@ -1716,6 +1757,9 @@ def head(self, n: int = 5) -> Self:
1716
1757
n: Number of rows to return. If a negative value is passed, return all rows
1717
1758
except the last `abs(n)`.
1718
1759
1760
+ Returns:
1761
+ A subset of the dataframe of shape (n, n_columns).
1762
+
1719
1763
Examples:
1720
1764
>>> import pandas as pd
1721
1765
>>> import polars as pl
@@ -1762,6 +1806,9 @@ def tail(self, n: int = 5) -> Self:
1762
1806
n: Number of rows to return. If a negative value is passed, return all rows
1763
1807
except the first `abs(n)`.
1764
1808
1809
+ Returns:
1810
+ A subset of the dataframe of shape (n, n_columns).
1811
+
1765
1812
Examples:
1766
1813
>>> import pandas as pd
1767
1814
>>> import polars as pl
@@ -1804,6 +1851,9 @@ def tail(self, n: int = 5) -> Self:
1804
1851
def drop (self , * columns : str | Iterable [str ], strict : bool = True ) -> Self :
1805
1852
"""Remove columns from the dataframe.
1806
1853
1854
+ Returns:
1855
+ The dataframe with the specified columns removed.
1856
+
1807
1857
Arguments:
1808
1858
*columns: Names of the columns that should be removed from the dataframe.
1809
1859
strict: Validate that all column names exist in the schema and throw an
@@ -1890,6 +1940,9 @@ def unique(
1890
1940
expensive to compute. Settings this to `True` blocks the possibility
1891
1941
to run on the streaming engine for Polars.
1892
1942
1943
+ Returns:
1944
+ The dataframe with the duplicate rows removed.
1945
+
1893
1946
Examples:
1894
1947
>>> import pandas as pd
1895
1948
>>> import polars as pl
@@ -1939,6 +1992,9 @@ def filter(
1939
1992
Each constraint will behave the same as `nw.col(name).eq(value)`, and will be implicitly
1940
1993
joined with the other filter conditions using &.
1941
1994
1995
+ Returns:
1996
+ The filtered dataframe.
1997
+
1942
1998
Examples:
1943
1999
>>> import pandas as pd
1944
2000
>>> import polars as pl
@@ -2153,6 +2209,9 @@ def sort(
2153
2209
specified per column by passing a sequence of booleans.
2154
2210
nulls_last: Place null values last.
2155
2211
2212
+ Returns:
2213
+ The sorted dataframe.
2214
+
2156
2215
Warning:
2157
2216
Unlike Polars, it is not possible to specify a sequence of booleans for
2158
2217
`nulls_last` in order to control per-column behaviour. Instead a single
@@ -2518,6 +2577,9 @@ def is_duplicated(self: Self) -> Series[Any]:
2518
2577
def is_empty (self : Self ) -> bool :
2519
2578
r"""Check if the dataframe is empty.
2520
2579
2580
+ Returns:
2581
+ A boolean indicating whether the dataframe is empty (True) or not (False).
2582
+
2521
2583
Examples:
2522
2584
>>> import narwhals as nw
2523
2585
>>> import pandas as pd
@@ -2600,6 +2662,9 @@ def is_unique(self: Self) -> Series[Any]:
2600
2662
def null_count (self : Self ) -> Self :
2601
2663
r"""Create a new DataFrame that shows the null counts per column.
2602
2664
2665
+ Returns:
2666
+ A dataframe of shape (1, n_columns).
2667
+
2603
2668
Notes:
2604
2669
pandas and Polars handle null values differently. Polars distinguishes
2605
2670
between NaN and Null, whereas pandas doesn't.
@@ -2651,6 +2716,13 @@ def null_count(self: Self) -> Self:
2651
2716
def item (self : Self , row : int | None = None , column : int | str | None = None ) -> Any :
2652
2717
r"""Return the DataFrame as a scalar, or return the element at the given row/column.
2653
2718
2719
+ Arguments:
2720
+ row: The *n*-th row.
2721
+ column: The column selected via an integer or a string (column name).
2722
+
2723
+ Returns:
2724
+ A scalar or the specified element in the dataframe.
2725
+
2654
2726
Notes:
2655
2727
If row/col not provided, this is equivalent to df[0,0], with a check that the shape is (1,1).
2656
2728
With row/col, this is equivalent to df[row,col].
@@ -2682,6 +2754,9 @@ def item(self: Self, row: int | None = None, column: int | str | None = None) ->
2682
2754
def clone (self ) -> Self :
2683
2755
r"""Create a copy of this DataFrame.
2684
2756
2757
+ Returns:
2758
+ An identical copy of the original dataframe.
2759
+
2685
2760
Examples:
2686
2761
>>> import narwhals as nw
2687
2762
>>> import pandas as pd
@@ -2721,6 +2796,9 @@ def gather_every(self: Self, n: int, offset: int = 0) -> Self:
2721
2796
n: Gather every *n*-th row.
2722
2797
offset: Starting index.
2723
2798
2799
+ Returns:
2800
+ The dataframe containing only the selected rows.
2801
+
2724
2802
Examples:
2725
2803
>>> import narwhals as nw
2726
2804
>>> import pandas as pd
@@ -2790,6 +2868,9 @@ def pivot(
2790
2868
separator: Used as separator/delimiter in generated column names in case of
2791
2869
multiple `values` columns.
2792
2870
2871
+ Returns:
2872
+ A new dataframe.
2873
+
2793
2874
Examples:
2794
2875
>>> import narwhals as nw
2795
2876
>>> import pandas as pd
@@ -2841,6 +2922,9 @@ def pivot(
2841
2922
def to_arrow (self : Self ) -> pa .Table :
2842
2923
r"""Convert to arrow table.
2843
2924
2925
+ Returns:
2926
+ A new PyArrow table.
2927
+
2844
2928
Examples:
2845
2929
>>> import narwhals as nw
2846
2930
>>> import pandas as pd
@@ -2890,6 +2974,9 @@ def sample(
2890
2974
seed: Seed for the random number generator. If set to None (default), a random
2891
2975
seed is generated for each sample operation.
2892
2976
2977
+ Returns:
2978
+ A new dataframe.
2979
+
2893
2980
Notes:
2894
2981
The results may not be consistent across libraries.
2895
2982
@@ -2956,6 +3043,9 @@ def unpivot(
2956
3043
variable_name: Name to give to the `variable` column. Defaults to "variable".
2957
3044
value_name: Name to give to the `value` column. Defaults to "value".
2958
3045
3046
+ Returns:
3047
+ The unpivoted dataframe.
3048
+
2959
3049
Notes:
2960
3050
If you're coming from pandas, this is similar to `pandas.DataFrame.melt`,
2961
3051
but with `index` replacing `id_vars` and `on` replacing `value_vars`.
0 commit comments