Q:

How to properly use pandas vectorization? 

According to an article, the vectorization is much faster than apply a function to a pandas dafaframe column. 
But I had a somehow special case like this:
import pandas as pd

df = pd. DataFrame({'IP': [ '1.0.64.2', '100.23.154.63', '54.62.1.3']})

def compare3rd(ip):
    """Check if the 3dr part of an IP is greater than 100 or not"""
    ip_3rd = ip.split('. ')[2]
    if int(ip_3rd) > 100:
        return True
    else:
        return False

# This works but very slow
df['check_results'] = df. IP.apply(lambda x: compare3rd(x))
print df

# This is supposed to be much faster
# But it doesn't work ...
df['check_results_2'] = compare3rd(df['IP'].values)
print df 

Full error traceback look like this:
Traceback (most recent call last):
  File "test.py", line 16, in <module>
    df['check_results_2'] = compare3rd(df['IP'].values)
  File "test.py", line 6, in compare3rd
    ip_3rd = ip.split('. ')[2]
AttributeError: 'numpy.ndarray' object has no attribute 'split'

My question is: how do I properly use this vectorization method in this case? 

A:

Check with str in pandas
df. IP.str.split('. ').str[2].astype(int)>100
0    False
1     True
2    False
Name: IP, dtype: bool

Since you mention vectorize
import numpy as np
np.vectorize(compare3rd)(df. IP.values)
array([False,  True, False])

