2022-12-14

How much time certain string mentioned in dataframe column

I have dictionary where key is color_name and value is list of color_name similar to mentioned as key color

all_colors = {
    'red': ['coral','burgundy'],
    'yellow':['mustard','lemon']}

I have pandas dataframe

import pandas as pd

df = pd.DataFrame(
    {'market_color': ['red',
                      'coral',
                      'burgundy',
                      'light red',
                      'mustard',
                      'lemon',
                      'red'],
     'color_id': [1, 2, 3, 4, 5, 6, 7]})

I want to count how much time color_name from all_colors and it's similarities mentioned in dataframe market_color column.

Expecting final dictionary like this all_colors_frequencies={'red':5,'yellow':2}

How i can achive it



No comments:

Post a Comment