BUG: do not use 'count' function name for value_counts() series/column name #53166
Closed
2 of 3 tasks
Labels
API - Consistency
Internal Consistency of API/Behavior
Bug
Closing Candidate
May be closeable, needs more eyeballs
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
On line 1 and/or line 3 value_counts/pandas assigns the name 'count' to the series/column.
'count' is a function name in pandas.
Line 6 reveals the issue with assigning the series/column name 'count'.
df = df[df.count > n]
-> Python/pandas error "cannot compare function and int".
Workaround (line 5) eliminates the error. I suppose df[df['count'] > n] is also a workaround.
My suggestion is to use a name other than 'count' (or any other pandas function name) when value_count/pandas creates the series/dataframe. Maybe 'Count'?
Expected Behavior
value_counts series/column name does not conflict with dataframe/series function name.
Installed Versions
INSTALLED VERSIONS
commit : 37ea63d
python : 3.11.3.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.90.1-microsoft-standard-WSL2
Version : #1 SMP Fri Jan 27 02:56:13 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.0.1
numpy : 1.24.3
pytz : 2023.3
dateutil : 2.8.2
setuptools : 66.0.0
pip : 23.1.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : 0.21.0
tzdata : 2023.3
qtpy : None
pyqt5 : None
None
The text was updated successfully, but these errors were encountered: