Bottom Page

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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  sort values of a column pandas karlito 2 445 Oct-22-2019, 06:11 AM
Last Post: karlito
  Pandas Import CSV count between numerical values within 1 Column ptaylor520 3 417 Jul-16-2019, 08:13 AM
Last Post: ptaylor520
  How to delete column if entire column values are "nan" Sri 4 890 Apr-13-2019, 12:16 PM
Last Post: Sri
  Splitting values in column in a pandas dataframe based on a condition hey_arnold 1 1,941 Jul-24-2018, 02:18 PM
Last Post: hey_arnold
  Get max values based on unique values in another list - python Antonio 8 2,457 Jun-12-2018, 07:49 PM
Last Post: Mekire
  Insert values into a column in the same table based on a criteria klllmmm 3 1,915 Apr-13-2017, 10:10 AM
Last Post: zivoni

Forum Jump:


Users browsing this thread: 1 Guest(s)