1
$\begingroup$

Is there a direct python pandas method to match values of series and update different series with some string ? I couldn’t find any direct method of doing it.

Here the match is to find a value in a series that is made up of given set of keywords and one mandatory keyword.

Example :

Here’s the keywords table :

KW:

case,kws,mand_kw,Friendly name
1,full|name|nm|txt|dsc[0-9],full,Full Name
2,first|name|nm|txt|dsc|[0-9],first,First Name
3,last|name|nm|txt|dsc|[0-9],last,Last Name
4,legal|name|nm|txt|dsc|[0-9],legal,Legal Name
5,nick|name|nm|txt|dsc|[0-9],nick,Nick Name

DF

_id,field_name,field_friendly_name,purpose_of_use,is_included_in_report
1,FullName,,,
2,xyz,,,
3,custname,,,
4,FullNm,,,
5,FirstName,,,
6,abc,,,
7,FirstNm,,,
8,LastName,,,
9,LastNm,,,
10,LegalName,,,
11,LegalNm,,,
12,NickName,,,
13,pqr,,,
14,NickNm,,,

For each of kws from KW find match in field_name in DF that it is made up of only keywords specified in kws and not any other words and a mandatorily should have a mand_kw keyword.

For example :

Case1:

Find all field_name that is only made up of these set of keywords “Full|name|nm|txt|dsc|[0-9]” and mandatory contains keyword "full" if so, assign field_friendly_name of KW - “Full Name” to field_friendly_name in DF and update is_included_in_report as true. If the value is not made of these keywords, then skip.

_id,field_name,field_friendly_name,purpose_of_use,is_included_in_report
1,fullname,Full Name,,TRUE
4,fullnm,Full Name,,TRUE
8,fullname74,Full Name,,TRUE
9,fulltxt,Full Name,,TRUE
$\endgroup$
0
$\begingroup$

here's what I've tried:

import pandas 
import re

KW = pd.read_csv("regex.csv")
DF = pd.read_csv("Default-Profile.csv")

for i in range (0,KW.kws.size): 
    for j in range (0,DF.field_name.size):
            if (DF.field_name.match(r"KW.kws[i]") == True && (DF.field_name.match(r"mand_kw[i]" == True)):
                    DF.field_friendly_name[j] = KW.field_friendly_name[i]
                    DF.is_included_in_report[j] = "True"
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.