title: Pandas get the row value by column name in an apply function in Python?
body: <p>I have the following dataframe:</p>
  <pre><code>&gt;&gt;&gt; d = {'route1': ['a', 'b'], 'route2': ['c', 'd'], 'val1': [1,2]}
  &gt;&gt;&gt; df = pd.DataFrame(data=d)
  &gt;&gt;&gt; df
    route1 route2  val1
  0      a      c     1
  1      b      d     2
  </code></pre>
  <p>What I am trying to do is to pass a list that contains some column names and print the row value associated with that columns:</p>
  <pre><code>&gt;&gt;&gt; def row_eval(row, list):
  &gt;&gt;&gt;    print(row.loc[list])
  </code></pre>
  <p>In the dataframe above, I first find all the columns that contains the name &quot;route&quot; and then apply the row_val func to each row. However I get the following err:</p>
  <pre><code>&gt;&gt;&gt; route_cols = [col for col in df.columns if 'route' in col]
  &gt;&gt;&gt; route_cols
  ['route1', 'route2']
  &gt;&gt;&gt; df.apply(lambda row: row_eval(row, route_cols)
  KeyError: &quot;None of [Index(['route1', 'route2'], dtype='object')] are in the [index]&quot;
  </code></pre>
  <p>Result should look like this:</p>
  <pre><code>route1 a
  route2 c
  
  route1 b
  route2 d
  
  </code></pre>