[Tutor] Help need with finding method to filter with regex and modify different column with correct match foung
Bharath Achar
bharath_achar at outlook.com
Fri Jul 3 08:57:36 EDT 2020
here's the code what I've tried:
import pandas
import re
for i in range (0,KW.kws.size):
for j in range (0,DF.field_name):
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"
--------------------------------------
Thanks,
Bharath Achar
Sr. Storage and Backup Consultant
Intel India pvt ltd, Bangalore.
Cell :: + 91 7259670196
Bharath_achar at outlook.com<mailto:Milind.Padelkar at lntinfotech.com>
--------------------------------------
________________________________
From: Bharath Achar
Sent: Friday, July 3, 2020 17:20
To: tutor at python.org <tutor at python.org>
Subject: Help need with finding method to filter with regex and modify different column with correct match foung
Hello,
Is there a direct python pandas method to match value 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.head(5)
Case
kws
mand_kw
field_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
Dataframe :
DF.head(14)
_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
fullname74
9
fullnm
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 keyword “Full|name|nm|txt|dsc|[0-9]” 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
fulldsc74
Full Name
TRUE
9
fulltxt
Full Name
TRUE
Regards,
Bharath Achar
--------------------------------------
Thanks,
Bharath Achar
Sr. Storage and Backup Consultant
Intel India pvt ltd, Bangalore.
Cell :: + 91 7259670196
Bharath_achar at outlook.com<mailto:Milind.Padelkar at lntinfotech.com>
--------------------------------------
More information about the Tutor
mailing list