I have a dataframe like so:
+-------+----------------+
|Name |Source |
+-------+----------------+
|Tom |clientA-incoming|
|Dick |clientB-incoming|
|Harry |c-abc-incoming |
and I would like to add a column slug
to end up with this dataframe:
+-------+----------------+--------+
|Name |Source |slug |
+-------+----------------+--------+
|Tom |clientA-incoming|clientA |
|Dick |clientB-incoming|clientB |
|Harry |c-abc-incoming |c-abc |
and I have a list of values that have the slugs in them:
slugs = ['clientA', 'clientB', 'c-abc']
basically im thinking something along the lines of this pseudocode:
for i in slugs:
if i in df['Source']:
df['Slug'] = i
can someone help me cross the finish line?
EDIT:
I want to update the slug
column with a value from the slugs
list. The specific value that goes into the slug
column is determined based off the Source
column.
For example, since slugs[0] = 'clientA'
and clientA is a substring of clientA-incoming
, I would like to update that row's value in the slug
column to clientA