Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

search for list of strings in pandas column

# Searching for strings and appending to dataframe.
search = ['FR-001', 'FR-002', 'FR-003', 'FR-004']
df['FR'] = df['Description'].str.findall('(' + '|'.join(search) + ')')
print (df)

                            Description                FR
0  AasfasfFR-001,asfasdfafsagsdg FR-002  [FR-001, FR-002]
1                 AasfasfFR-004, FR-002  [FR-004, FR-002]
2         AasfasfFR-02,asfasdfafsagsdg                 []
3  AasfasfFR-001,asfasdfafsagsdg FR-003  [FR-001, FR-003]
4  AasfasfFR-004,asfasdfafsagsdg FR-002  [FR-004, FR-002]

#To filter out empty list
df = df[df['FR'].astype(bool)]
print (df)

                            Description                FR
0  AasfasfFR-001,asfasdfafsagsdg FR-002  [FR-001, FR-002]
1                 AasfasfFR-004, FR-002  [FR-004, FR-002]
3  AasfasfFR-001,asfasdfafsagsdg FR-003  [FR-001, FR-003]
4  AasfasfFR-004,asfasdfafsagsdg FR-002  [FR-004, FR-002]
Comment

PREVIOUS NEXT
Code Example
Python :: set comprehension 
Python :: how to change series datatype from object to float 
Python :: how delete an entry tkinter 
Python :: generate a list with random length and with random numbers python 
Python :: joblib example 
Python :: iterating a list in python 
Python :: conditional and in python 
Python :: pandas show all dataframe method 
Python :: fraction to float 
Python :: add row to dataframe 
Python :: circle python programe 
Python :: python replace negative infinity 
Python :: python monitor directory for files count 
Python :: how to create copy of all objects in list python 
Python :: clipboard python 
Python :: run python in c ++ 
Python :: python dataframe add rank column 
Python :: keras name model 
Python :: how to change an integer to a string in python permanently 
Python :: join function python 
Python :: model.predict Decision Tree Model 
Python :: python range() float 
Python :: python list function 
Python :: invalid syntax python else 
Python :: recursion python examples 
Python :: keras model 2 outputs 
Python :: pyqt click through window 
Python :: www.pd.date_range 
Python :: remove figure label 
Python :: blender change text during animation 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =