polars.DataFrame.get_column
-
Get a single column by name.
- Parameters:
-
- name
-
String name of the column to retrieve.
- default
-
Value to return if the column does not exist; if not explicitly set and the column is not present a
ColumnNotFoundErrorexception is raised.
- Returns:
-
- Series (or arbitrary default value, if specified).
See also
Examples
>>> df = pl.DataFrame({"foo": [1, 2, 3], "bar": [4, 5, 6]}) >>> df.get_column("foo") shape: (3,) Series: 'foo' [i64] [ 1 2 3 ]Missing column handling; can optionally provide an arbitrary default value to the method (otherwise a
ColumnNotFoundErrorexception is raised).>>> df.get_column("baz", default=pl.Series("baz", ["?", "?", "?"])) shape: (3,) Series: 'baz' [str] [ "?" "?" "?" ] >>> res = df.get_column("baz", default=None) >>> res is None True
DataFrame.get_column(
name: str,
*,
default: Any | NoDefault = <no_default>,
) → Series | Any
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/dataframe/api/polars.DataFrame.get_column.html