Skip to content Skip to sidebar Skip to footer

Counting Appearances Of Multiple Substrings In A Cell Pandas

I have a column that contains rather lengthy strings. Each of the string may or may not contain substrics. Such substrings as 'H 07', 'H 06' or 'F 13' may or may not appear in a da

Solution 1:

something like:

substrs = [...]
def f(cell_value):
    return {k: v for k, v in ((s, cell_value.count(s)) for s in substrs) if v}
df.column.apply(f)

Post a Comment for "Counting Appearances Of Multiple Substrings In A Cell Pandas"