apply was renamed to .map_elements() some time ago.

Previous versions printed a deprecation warning, but it was eventually removed after a grace period.

You're likely looking at the docs for an older version of Polars, but there is a "version switcher" on the docs site:

As for the actual task, you can also do it natively using .dt.to_string()

import datetime
import polars as pl

pl.select(
   pl.lit(str(datetime.datetime.now()))
     .str.to_datetime()
     .dt.to_string("%A")
)      
shape: (1, 1)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ literal β”‚
β”‚ ---     β”‚
β”‚ str     β”‚
β•žβ•β•β•β•β•β•β•β•β•β•‘
β”‚ Tuesday β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Answer from jqurious on Stack Overflow
🌐
GitHub
github.com β€Ί pola-rs β€Ί polars β€Ί issues β€Ί 24781
Polars.Exp.apply has no attribute apply Β· Issue #24781 Β· pola-rs/polars
October 6, 2025 - I have confirmed this bug exists on the latest version of Polars. df = pl.DataFrame( { "a": [1, 2, 3, 1], "b": ["a", "b", "c", "c"], } ) df.with_columns( pl.col("a").apply(lambda x: x * 2).alias("a_times_2"), ) **AttributeError: 'Expr' object has no attribute 'apply'** I wanted to use the function apply in my code, but I realized that I receive an error nonethelss .
Author Β  pola-rs
Discussions

python - Using apply in polars - Stack Overflow
8 Using Polars with Python and being thrown the following exception: AttributeError: 'Expr' object has no attribute 'apply' More on stackoverflow.com
🌐 stackoverflow.com
ColumnTransformer.fit() fails on polars.DataFrame: AttributeError: 'DataFrame' object has no attribute 'size'
Describe the bug Fitting a sklearn.compose.ColumnTransformer with more than one transformer on a polars.DataFrame yields the error: AttributeError: 'DataFrame' object has no attribute '... More on github.com
🌐 github.com
2
September 11, 2025
AttributeError: 'DataFrame' object has no attribute 'get'
Couldn't load subscription status. Retry Β· There was an error while loading. Please reload this page More on github.com
🌐 github.com
2
June 6, 2023
'Expr' object has no attribute 'apply'
Description pl.col('fild1').apply( base64θ§£ε―†ηš„δ»£η  ) 会ζŠ₯ι”™'Expr' object has no attribute 'apply'是为ε•₯ Link No response More on github.com
🌐 github.com
2
December 23, 2024
🌐
GitHub
github.com β€Ί pola-rs β€Ί polars β€Ί issues β€Ί 10744
Rename all `apply` functions to `map_*` Β· Issue #10744 Β· pola-rs/polars
August 26, 2023 - In #10678, Ritchie mentions the reason for moving away from the apply naming: Pandas apply will have opposite behavior of polars. We chose apply because people were so familiar with it in pandas. N...
Author Β  pola-rs
🌐
JetBrains
youtrack.jetbrains.com β€Ί issue β€Ί PY-63683 β€Ί Polars-DataFrames-cant-be-viewed-as-DataFrame-in-PyCharm-Community
Polars DataFrames can't be viewed 'as ...
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
Polars
docs.pola.rs β€Ί api β€Ί python β€Ί version β€Ί 0.18 β€Ί reference β€Ί expressions β€Ί api β€Ί polars.Expr.apply.html
polars.Expr.apply β€” Polars documentation
Apply a custom/user-defined function (UDF) in a GroupBy or Projection context Β· This method is much slower than the native expressions API. Only use it if you cannot implement your logic otherwise
Top answer
1 of 2
8

pl.Expr.apply was deprecated in favour of pl.Expr.map_elements in Polars release 0.19.0. Recently, pl.Expr.apply was removed in the release of Polars 1.0.0.

You can adapt your code to the new version as follows.

Copydf.with_columns(
    pl.col("AH_PROC_REALIZADO")
    .map_elements(get_procedure_description, return_dtype=pl.String)
    .alias("proced_descr")
)
2 of 2
3

If you really want to apply python function then you can use map_elements(). However, using native polars expression is always preferrable.

In your case I'd suggest to look at replace() or replace_strict().

If you would want to just search by AH_PROC_REALIZADO column you could use simple replace_strict():

Copydf = pl.DataFrame({
    "AH_PROC_REALIZADO": ["30408", "410010065", "410010111", "XXXX"]
})

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ AH_PROC_REALIZADO β”‚
β”‚ ---               β”‚
β”‚ str               β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•‘
β”‚ 30408             β”‚
β”‚ 410010065         β”‚
β”‚ 410010111         β”‚
β”‚ XXXX              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

df.with_columns(
    pl.col("AH_PROC_REALIZADO")
    .replace_strict(proceds, default=None)
    .alias("proced_descr")
)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ AH_PROC_REALIZADO ┆ proced_descr                   β”‚
β”‚ ---               ┆ ---                            β”‚
β”‚ str               ┆ str                            β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•ͺ════════════════════════════════║
β”‚ 30408             ┆ QUIMIOTERAPIA                  β”‚
β”‚ 410010065         ┆ MASTECTOMIA SIMPLES            β”‚
β”‚ 410010111         ┆ SETORECTOMIA / QUADRANTECTOMIA β”‚
β”‚ XXXX              ┆ null                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The problem with your use case is that, as far as I understand, you want to search by prefix of the strings in AH_PROC_REALIZADO column. In that case you could probably adjust the solution to:

  • itertools.groupby() to transform proceds dictionary into dictionary of dictionaries where high level keys are length of the key.
  • replace_strict() to search for product description.
  • coalesce() to combine results into final column.
Copyfrom itertools import groupby

mappings = {k: dict(g) for k, g in groupby(proceds.items(), lambda x: len(x[0]))}

df = pl.DataFrame({
    "AH_PROC_REALIZADO": ["30408_____", "410010065_____", "410010111____", "XXXX"]
})

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ AH_PROC_REALIZADO β”‚
β”‚ ---               β”‚
β”‚ str               β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•‘
β”‚ 30408_____        β”‚
β”‚ 410010065_____    β”‚
β”‚ 410010111____     β”‚
β”‚ XXXX              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

df.with_columns(
    pl.coalesce(
        pl.col("AH_PROC_REALIZADO").str.head(k).replace_strict(m, default=None) for k, m in mappings.items()
    )
    .alias("proced_descr")
)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ AH_PROC_REALIZADO ┆ proced_descr                   β”‚
β”‚ ---               ┆ ---                            β”‚
β”‚ str               ┆ str                            β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•ͺ════════════════════════════════║
β”‚ 30408_____        ┆ QUIMIOTERAPIA                  β”‚
β”‚ 410010065_____    ┆ MASTECTOMIA SIMPLES            β”‚
β”‚ 410010111____     ┆ SETORECTOMIA / QUADRANTECTOMIA β”‚
β”‚ XXXX              ┆ null                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
🌐
GitHub
github.com β€Ί scikit-learn β€Ί scikit-learn β€Ί issues β€Ί 32155
ColumnTransformer.fit() fails on polars.DataFrame: AttributeError: 'DataFrame' object has no attribute 'size' Β· Issue #32155 Β· scikit-learn/scikit-learn
September 11, 2025 - Describe the bug Fitting a sklearn.compose.ColumnTransformer with more than one transformer on a polars.DataFrame yields the error: AttributeError: 'DataFrame' object has no attribute '...
Author Β  scikit-learn
🌐
JetBrains
youtrack.jetbrains.com β€Ί issue β€Ί DS-5668 β€Ί Polars-tables-are-broken-in-data-vision-with-polars-0.16.13
Polars tables are broken in data vision with polars 0.16.13
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
Find elsewhere
🌐
GitHub
github.com β€Ί mwaskom β€Ί seaborn β€Ί issues β€Ί 3379
AttributeError: 'DataFrame' object has no attribute 'get' Β· Issue #3379 Β· mwaskom/seaborn
June 6, 2023 - AttributeError: 'DataFrame' object has no attribute 'get'#3379 Β· Copy link Β· nick-youngblut Β· opened Β· on Jun 6, 2023 Β· Issue body actions Β· It appears that seaborn somewhat supports polars.DataFrame objects, such as: iris = pl.read_csv("data/iris.csv") p = sns.displot( data=iris, x="sepal_width", hue="species", col="species", height=3, aspect=1, alpha=1 ) ...but not fully: p = sns.catplot( data=iris, x="species", y="sepal_width", kind="box", height=3, aspect=1.3 ) The error: 3185 p = _CategoricalPlotter() 3186 p.require_numeric = plotter_class.require_numeric -> 3187 p.establish_variables(x_, y_, hue, data, orient, order, hue_order) 3188 if ( 3189 order is not None 3190 or (sharex and p.orient == "v") 3191 or (sharey and p.orient == "h") 3192 ): 3193 # Sync categorical axis between facets to have the same categories 3194 order = p.group_names ...
Author Β  mwaskom
🌐
Polars
docs.pola.rs β€Ί api β€Ί python β€Ί version β€Ί 0.18 β€Ί reference β€Ί dataframe β€Ί api β€Ί polars.DataFrame.apply.html
polars.DataFrame.apply β€” Polars documentation
Apply a custom/user-defined function (UDF) over the rows of the DataFrame Β· This method is much slower than the native expressions API. Only use it if you cannot implement your logic otherwise
🌐
Polars
docs.pola.rs β€Ί api β€Ί python β€Ί version β€Ί 0.18 β€Ί reference β€Ί expressions β€Ί api β€Ί polars.Expr.map.html
polars.Expr.map β€” Polars documentation
Apply a custom python function to a Series or sequence of Series Β· The output of this custom function must be a Series. If you want to apply a custom function elementwise over single values, see apply(). A use case for map is when you want to transform an expression with a third-party library
🌐
GitHub
github.com β€Ί pola-rs β€Ί polars β€Ί issues β€Ί 20410
'Expr' object has no attribute 'apply' Β· Issue #20410 Β· pola-rs/polars
December 23, 2024 - Description pl.col('fild1').apply( base64θ§£ε―†ηš„δ»£η  ) 会ζŠ₯ι”™'Expr' object has no attribute 'apply'是为ε•₯ Link No response
Author Β  pola-rs
🌐
GitHub
github.com β€Ί pola-rs β€Ί polars β€Ί issues β€Ί 6117
Rationalize with_column & with_columns Β· Issue #6117 Β· pola-rs/polars
January 8, 2023 - Problem description Initial discussion was on Discord, moving here so everyone can join. The DataFrame methods with_column and with_columns tend to be used quite often, as these are, together with select, the primary way to run expressio...
Author Β  pola-rs
🌐
GitHub
github.com β€Ί pola-rs β€Ί polars β€Ί issues β€Ί 3481
Lazy join fails with `AttributeError: _ldf` Β· Issue #3481 Β· pola-rs/polars
May 23, 2022 - A join between two dataframes works in eager mode, but fails in lazy mode with an AttributeError: _ldf. import polars as pl df_left = pl.DataFrame({ "Id": [1, 2, 3, 4], "Names": ["A", "B", "C", "D"], }) df_right = pl.DataFrame({ "Id": [1, 3], "Tags": ["xxx", "yyy"] }) print(df_left.join(df_right, on="Id")) # Works print(df_left.lazy().join(df_right, on="Id")) # Fails!
Author Β  pola-rs
🌐
GitHub
github.com β€Ί pola-rs β€Ί polars β€Ί issues β€Ί 4740
set_with_columns_kwargs() does not exist, but recommended Β· Issue #4740 Β· pola-rs/polars
September 6, 2022 - Polars version checks I have checked that this issue has not already been reported. I have confirmed this bug exists on the latest version of polars. Issue Description .with_columns(**named_kwargs) throws an error RuntimeError: **kwargs ...
Author Β  pola-rs
🌐
GitHub
github.com β€Ί pola-rs β€Ί polars β€Ί issues β€Ί 6080
Unreliable schema for datetime columns and error in .glimpse() Β· Issue #6080 Β· pola-rs/polars
January 6, 2023 - Polars does not seem to handle python datetime and pd.datetime objects reliably. ... import pandas as pd import numpy as np pd.DataFrame({'Date':['2023-01-01']}).astype({'Date':'datetime64[ns]'}).pipe(pl.from_pandas).glimpse()
Author Β  pola-rs
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί "'dataframe' object has no attribute" issue
r/learnpython on Reddit: "'DataFrame' object has no attribute" Issue
October 30, 2020 -

I am in university and am taking a special topics class regarding AI. I have zero knowledge about Python, how it works, or what anything means.

A project for the class involves manipulating Bayesian networks to predict how many and which individuals die upon the sinking of a ship. This is the code I am supposed to manipulate:

##EDIT VARIABLES TO THE VARIABLES OF INTEREST
train_var = train.loc[:,['Survived','Sex']]  
test_var = test.loc[:,['Sex']]  
BayesNet = BayesianModel([('Sex','Survived')])

I am supposed to add another variable, 'Pclass,' to the mix, paying attention to the order for causation. I have added that variable to every line of this code in every way imaginable and consistently get an error from this line:

predictions = pandas.DataFrame({'PassengerId': test.PassengerId,'Survived': hypothesis.Survived.tolist()})
predictions

For example, the error I get for this version of the code:

train_var = train.loc[:,['Survived','Pclass','Sex']]  
test_var = test.loc[:,['Pclass']]  
BayesNet = BayesianModel([('Sex','Pclass','Survived')])

is this:

AttributeError                            Traceback (most recent call last)
<ipython-input-98-16d9eb9451f7> in <module>
----> 1 predictions = pandas.DataFrame({'PassengerId': test.PassengerId,'Survived': hypothesis.Survived.tolist()})
      2 predictions

/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5137             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5138                 return self[name]
-> 5139             return object.__getattribute__(self, name)
   5140 
   5141     def __setattr__(self, name: str, value) -> None:

AttributeError: 'DataFrame' object has no attribute 'Survived'

Honestly, I have no idea wtf any of this means. I have tried googling this issue and have come up with nothing.

Any help would be greatly appreciated. I know it's a lot.

🌐
Polars
docs.pola.rs β€Ί py-polars β€Ί html β€Ί reference β€Ί dataframe β€Ί index.html
DataFrame β€” Polars documentation
When the by argument is given, polars can not check sortedness by the metadata and has to do a full scan on the index column to verify data is sorted. This is expensive. If you are sure the data within the groups is sorted, you can set this to False. Doing so incorrectly will lead to incorrect output ... Object you can call .agg on to aggregate by groups, the result of which will be sorted by index_column (but note that if by columns are passed, it will only be sorted within each by group).