You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At this moment, Pandas allows duplicate column names. This can potentially lead to problems, when user expects to receive pd.Series when asking for a single column, if they are not aware that the column names are duplicated.
This is especially problematic with automatic processing, where column duplication can easily appear as a consequence of some bug.
Expected Output
Better solution: at the time of creating the pd.DataFrameor adding new column to pd.DataFrame, when the column name is duplicated, the code fails with an error message informing about the duplicated name. This is easy to implement and failing fast is usually a good practice.
Worse solutions:
Similar as above, but instead of crashing, the warning message is displayed both: (a) when initializing duplicated column, and (b) during any operation that calls the duplicated column. In such case user would be aware that the behaviour of Pandas may give different results then if he was calling by the non-duplicated column name.
Silently add suffixes to duplicated column names when they appear, as for example, R does. Best to be done with some warning or info message.
Examples:
Python's DataTable by default silently overwrites the duplicated column (bad):
Code Sample, a copy-pastable example if possible
Hopefully:
But...
Problem description
At this moment, Pandas allows duplicate column names. This can potentially lead to problems, when user expects to receive
pd.Series
when asking for a single column, if they are not aware that the column names are duplicated.This is especially problematic with automatic processing, where column duplication can easily appear as a consequence of some bug.
Expected Output
Better solution: at the time of creating the
pd.DataFrame
or adding new column topd.DataFrame
, when the column name is duplicated, the code fails with an error message informing about the duplicated name. This is easy to implement and failing fast is usually a good practice.Worse solutions:
Examples:
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.3.final.0
python-bits : 64
OS : Linux
OS-release : 5.0.0-25-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 0.25.1
numpy : 1.17.1
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.3
setuptools : 41.2.0
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
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
The text was updated successfully, but these errors were encountered: