-1

I am looking for a workaround in an issue I have with a pd.dataframe I am creating. I am looking to have values in my dataframe selected based on their string values.

Here is some example code

'Main.loc[Main['Discrepancy Description'].str.contains('seat',case=False),'Issue']='Seats'

This says any time the column "discrepancy description' contains "seat" to make the value of Issues equal to "Seats".

I am curious if there's a way to exclude other parameters? As in, have the code not return "Seat" if the string says "seat belt" or something similar. Is there a way to exclude other values? Thank you in advance.

dom ryan
  • 27
  • 4

1 Answers1

0

I was able to solve this by using the df search up inversion (~), which looks as follows:

    Main.loc[~Main['Discrepancy Description'].str.contains('some cell value',na=False,case=False),'Other Column'] ='Desired value to be changed to'

This allowed me to quickly sort thorugh cells in excel that did not contain the parameter in the code. This was better explained in this post: Search for "does-not-contain" on a DataFrame in pandas

dom ryan
  • 27
  • 4