str.find fails to return integers
As per the docs it should return Series/Index of integer values
Code Sample, a copy-pastable example if possible
df[:5]
0 1
0 ZAR12015 FastEthernet2/0/38
1 AFA12286 FastEthernet4/0/22
2 CAA12029 FastEthernet2/0/35
3 IFAA2302 FastEthernet4/0/14
4 HFQ12009 FastEthernet5/38
df.loc[:,"1"].str.find("Ether")
6982 4.0
6983 4.0
6984 4.0
Name: 1, dtype: float64
df.loc[:,"1"].apply( lambda x : x[x.find("Ether"):])
AttributeError Traceback (most recent call last)
<ipython-input-39-73570bc63928> in <module>()
----> 1 df.loc[:,"1"].apply( lambda x : x[x.find("Ether"):])
C:\Users\X91437\Documents\Program Files\Anaconda\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds)
2290 else:
2291 values = self.asobject
-> 2292 mapped = lib.map_infer(values, f, convert=convert_dtype)
2293
2294 if len(mapped) and isinstance(mapped[0], Series):
pandas\src\inference.pyx in pandas.lib.map_infer (pandas\lib.c:66116)()
<ipython-input-39-73570bc63928> in <lambda>(x)
----> 1 df.loc[:,"1"].apply( lambda x : x[x.find("Ether"):])
AttributeError: 'float' object has no attribute 'find'
Your code here
#### Expected Output
6982 4
6983 4
6984 4
Name: 1, dtype: int
Output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.19.1
nose: 1.3.7
pip: 8.1.2
setuptools: 23.0.0
Cython: 0.24
numpy: 1.11.1
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 5.2.1
sphinx: 1.3.1
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: 1.1.0
tables: 3.2.2
numexpr: 2.6.0
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.2
lxml: 3.6.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.40.0
pandas_datareader: None
Comment From: littlegreenbean33
looks like the inferred types ( float ) is not correct
as this works
df.loc[:,"1"].apply( lambda x : (str(x))[ str(x).find("Ether")+8:] ) 0 2/0/38 1 4/0/22 2 2/0/35 3 4/0/14 4 5/38
Comment From: jreback
your example works fine.
In [16]: df
Out[16]:
1 2
0
0 ZAR12015 FastEthernet2/0/38
1 AFA12286 FastEthernet4/0/22
2 CAA12029 FastEthernet2/0/35
3 IFAA2302 FastEthernet4/0/14
4 HFQ12009 FastEthernet5/38
In [17]: df[2].str.find('Ether')
Out[17]:
0
0 4
1 4
2 4
3 4
4 4
Name: 2, dtype: int64
using .apply
esp with a string accessor is non-idiomatic.