Python Forum

Full Version: Counter to keep track how many times values in a list appear in each row in a column
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import pandas as pd


words = [
    "robot",
    "automation",
    "collaborative",
    "Artificial Intelligence",
    "technology",
    "Computing",
    "autonomous",
    "automobile",
    "cobots",
    "AI",
    "Integration",
    "robotics",
    "machine learning",
    "machine",
    "vision systems",
    "systems",
    "computerized",
    "programmed",
    "neural network",
    "tech",
]

data = [
    [
        "robotm, automation, collaborative ,Artificial, Intelligence, technology, Computing, autonomous ,automobile, cobots, AI, Integration, robotics ,machine learning, machine, vision systems, systems, computerized, programmed, neural network, tech"
    ],
    [
        "robotm, automation, collaborative ,Artificial, Intelligence, technology, Computing, autonomous ,automobile, cobots, AI, Integration, robotics ,machine learning, machine, vision systems, systems, computerized, programmed, neural network, tech, hello, lala, hi, cat"
    ],
    [
        "dog, bird, cards, pet, mama, robotm, automation, collaborative ,Artificial, Intelligence, technology, Computing, autonomous ,automobile, cobots, AI, Integration, robotics ,machine learning, machine, vision systems, systems, computerized, programmed, neural network, tech, fish, ocean, river, sky"
    ],
]
df = pd.DataFrame(data, columns=["text"])

count = 0
for text in df["text"].iteritems():
    if words in text:
        count += 1
        print(count)

# output goal
# index[0]: 10
# index[1]: 13
# index[2]: 15
Output:
blank