Description
Code
import pandas as pd
df=pd.DataFrame([[1,2,3],[4,5,6]])
df.index=['a','b'] #I was suspicious of the index
def bla(x):
print('Applying to:',x)
return x+1
df.applymap(bla)
Output
Applying to: 1
Applying to: 4
Applying to: 1
Applying to: 4
Applying to: 2
Applying to: 5
Applying to: 3
Applying to: 6
0 1 2
a 2 3 4
b 5 6 7
Problem description
Seems applymap
is calling on the first column twice. There is no effect in the end result, just a run-time hit as far as I can tell. This affects functions with side effects, as well as runtime.
Expected Output
Applying to: 1
Applying to: 4
Applying to: 2
Applying to: 5
Applying to: 3
Applying to: 6
0 1 2
a 2 3 4
b 5 6 7
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.5.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.9.0-8-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8
pandas: 0.19.2
nose: 1.3.7
pip: 9.0.1
setuptools: 36.0.1
Cython: None
numpy: 1.12.1
scipy: 0.18.1
statsmodels: None
xarray: None
IPython: 6.1.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: 3.3.0
numexpr: 2.6.1
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.5.3
html5lib: 0.999999999
httplib2: 0.9.2
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
boto: None
pandas_datareader: None