Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this issue exists on the latest version of pandas.
-
I have confirmed this issue exists on the main branch of pandas.
Reproducible Example
I'm experiencing a slowdown compared to prior versions when assigning a DataFrame in a for loop :
import pandas as pd
def foo(df):
for idx in df.index:
df.at[idx, "bar"] = 3
df = pd.DataFrame(range(10000))
df["bar"] = 0
%timeit foo(df)
# pandas 1.5.1 : 506 ms ± 20.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
My use case is more complex and the loop can't be vectorized, that's why I'm using a for loop instead.
Installed Versions
INSTALLED VERSIONS
commit : 91111fd
python : 3.9.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.0-19-amd64
Version : #1 SMP Debian 5.10.149-2 (2022-10-21)
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : fr_FR.UTF-8
LOCALE : fr_FR.UTF-8
pandas : 1.5.1
numpy : 1.23.3
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 65.4.0
pip : 22.2.2
Cython : 0.29.32
pytest : 6.2.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.3
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.5.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.0
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.1
snappy : None
sqlalchemy : 1.4.41
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None
Prior Performance
%timeit foo(df)
# pandas 1.4.4 : 67 ms ± 8.92 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)