Jul-22-2020, 12:28 PM
Hi,
I have below sentence and I want to check the sub-sentence (continuous appearance of words.
Example:
main_sentence= "The robot turn on and put on to machine AP0678A and started process IS=56"
sub_sentence = "put on to machine AP0678A and started process"
I use below code, but it is putting in every row
I have below sentence and I want to check the sub-sentence (continuous appearance of words.
Example:
main_sentence= "The robot turn on and put on to machine AP0678A and started process IS=56"
sub_sentence = "put on to machine AP0678A and started process"
I use below code, but it is putting in every row
Code Status Rank BA AA machine AP0678A process now 2 BA The rob, fix AP0678A testing 8 BA The initialize comp AP0678A start 6 JK A machine PK0678A end vent ID=56 23 JK The shutdown machine PK0678A test proc 45 LP The machine UG5678A started coat 9 LP The re start UG5678A testing 102 BA The power on AP0678A send report kit 563
import pandas as pd df = pd.read_csv(r'D:\PythonCodes\machine2.csv') df['final_status'] = 'NA' for idx, row in df.iterrows(): if "machine AP0678A processs" in row['Status']: df['final_status'] = 'AP0678A' elif "initialize comp AP0678A" in row['Status']: df['final_status'] = 'AP0678A' elif "comp AP0678A" in row['Status']: df['final_status'] = 'AP0678A' elif "power on AP0678A send report" in row['Status']: df['final_status'] = 'AP0678A'
Code Status Rank final_status BA AA machine AP0678A process now 2 AP0678A BA The rob, fix AP0678A testing 8 AP0678A BA The initialize comp AP0678A start 6 AP0678A JK A machine PK0678A end vent ID=56 23 NA JK The shutdown machine PK0678A test proc 45 NA LP The machine UG5678A started coat NA NA LP The re start UG5678A testing 102 NA BA The power on AP0678A send report kit 563 AP0678A