pandas.col#

pandas.col(col_name)[source]#

Generate deferred object representing a column of a DataFrame.

Any place which accepts lambda df: df[col_name], such as DataFrame.assign() or DataFrame.loc(), can also accept pd.col(col_name).

Parameters:
col_nameHashable

Column name.

Returns:
pandas.api.typing.Expression

A deferred object representing a column of a DataFrame.

See also

DataFrame.query

Query columns of a dataframe using string expressions.

Examples

You can use col in assign.

>>> df = pd.DataFrame({"name": ["beluga", "narwhal"], "speed": [100, 110]})
>>> df.assign(name_titlecase=pd.col("name").str.title())
      name  speed name_titlecase
0   beluga    100         Beluga
1  narwhal    110        Narwhal

You can also use it for filtering.

>>> df.loc[pd.col("speed") > 105]
      name  speed
1  narwhal    110