Home > Software design >  Data frame specific row value selection
Data frame specific row value selection

Time:12-27

I have a df with multiple column. One of the column-ID value as look like INSMO* and this will be varying. "INS" is constant. How do i check INS* present in the column or notenter image description here

CodePudding user response:

I would do startswith:

out = df[df['col'].str.startswith('INS')]

Or:

out = df[df.iloc[:, 1].str.startswith('INS')]

CodePudding user response:

Try this:

has_it = df['whatever the second column is named'].str.contains(r'^INS', regex=True)

CodePudding user response:

In your case just do

out = df[df['col'].str[:3].eq('INS')]
  • Related