Python Forum
Counter to keep track how many times values in a list appear in each row in a column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Counter to keep track how many times values in a list appear in each row in a column
#1
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
Reply


Messages In This Thread
Counter to keep track how many times values in a list appear in each row in a column - by chief - Mar-24-2020, 08:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  attempt to split values from within a dataframe column mbrown009 8 2,351 Apr-10-2023, 02:06 AM
Last Post: mbrown009
  Increase df column values decimals SriRajesh 2 1,108 Nov-14-2022, 05:20 PM
Last Post: deanhystad
  Changing Values in a List DaveG 1 1,289 Apr-04-2022, 03:38 PM
Last Post: jefsummers
  pandas: Compute the % of the unique values in a column JaneTan 1 1,779 Oct-25-2021, 07:55 PM
Last Post: jefsummers
Question [Solved] How to refer to dataframe column name based on a list lorensa74 1 2,259 May-17-2021, 07:02 AM
Last Post: lorensa74
  Assigning Column nunique values to another DataFrame column Pythonito 0 1,716 Jun-25-2020, 05:04 PM
Last Post: Pythonito
  sort values of a column pandas karlito 2 2,501 Oct-22-2019, 06:11 AM
Last Post: karlito
  Pandas Import CSV count between numerical values within 1 Column ptaylor520 3 2,651 Jul-16-2019, 08:13 AM
Last Post: ptaylor520
  How to delete column if entire column values are "nan" Sri 4 3,718 Apr-13-2019, 12:16 PM
Last Post: Sri
  Splitting values in column in a pandas dataframe based on a condition hey_arnold 1 4,168 Jul-24-2018, 02:18 PM
Last Post: hey_arnold

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020