![]() |
Counter to keep track how many times values in a list appear in each row in a column - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Counter to keep track how many times values in a list appear in each row in a column (/thread-25251.html) |
Counter to keep track how many times values in a list appear in each row in a column - chief - Mar-24-2020 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
|