1

I have 2 dfs:

Sample of df1: s12

BacksGas_Flow_sccm  ContextID   StepID  Time_Elapsed
46.6796875           7289972     12       25.443
46.6796875           7289972     12       26.443

Sample of df2: step12

ContextID   BacksGas_Flow_sccm  StepID  Time_Elapsed
7289973         46.6796875        12       26.388
7289973         46.6796875        12       27.388

Since the BacksGas_Flow_sccm is on different positions in both the dfs, I would like to know as to how can I extract the column using df.columns.str.contains('Flow')

I tried doing:

s12.columns[s12.columns.str.contains('Flow')]

but it just gives the following output:

Index(['BacksGas_Flow_sccm'], dtype='object')

I would like the entire column to be extracted. How can this be done?

some_programmer
  • 3,268
  • 4
  • 24
  • 59

1 Answers1

1

You are close, use DataFrame.loc with : for get all rows and columns filtered by conditions:

s12.loc[:, s12.columns.str.contains('Flow')]

Another idea is select by columns names:

cols = s12.columns[s12.columns.str.contains('Flow')]
s12[cols]
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252