def str_count(arr, pat, flags=0):
 regex = re.compile(pat, flags=flags)
 f = (lambda x: len(regex.findall(x)))
 return _na_map(f, arr, dtype=int)

def str_count ( arr , pat , flags = 0 ) : regex = re . compile ( pat , flags = flags ) f = ( lambda x : len ( regex . findall ( x ) ) ) return _na_map ( f , arr , dtype = int )
count occurrences of pattern in each string of the series/index .