-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame.transform(dict) drops columns not mentioned in the dict #38296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Returning only 3 columns is the desired behavior, you can perform your operation as:
|
Thanks, but I consider this a rather unfavourable workaround.
Out of curiosity why did you say this is not a Bug? |
@tilusnet axis is rows this is defined behavior and not a bug you can use .assign to achieve fluent behavior easily |
Thanks @jreback , I wasn't aware of .assign's side effect achieving data transformation. I am sorry to insist on how misleading/incomplete the .transform documentation is. Is there a better official documentation about the Transform feature apart from this article here? |
you are welcome to submit a doc update if you would like though there is extensive documentation |
I'll consider helping with the docs once I truly understand it myself first. |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
I may have a dataframe with 100 columns, of which I want to transform 3.
DataFrame.transform()
accepts a dict with column -> function mappings, therefore my intuition is to provide 3 mappings for the 3 columns I want transformed. However, upon providing such a mapping dict, the function drops the non mentioned 97 columns.Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Problem description
The transformation lost the 97 columns for which there was no transformation mapping provided.
The natural intuition is to preserve all columns that were not mentioned in the transformation.
Expected Output
A dataframe containing all 100 columns: the 3 transformed columns with the rest of the 97 columns untouched.
The current implementation returns 3 columns.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 67a3d42
python : 3.7.8.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-123-generic
Version : #126~16.04.1-Ubuntu SMP Wed Oct 21 13:48:05 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.1.4
numpy : 1.19.4
pytz : 2020.4
dateutil : 2.8.1
pip : 20.3
setuptools : 49.6.0.post20201009
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 : 5.8.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: