title: Pandas: How to do operations using loc with multiple columns and format the results
body: <p><a href="https://github.com/veekun/pokedex/blob/master/pokedex/data/csv/abilities.csv" rel="nofollow noreferrer">Here</a> is the csv file I using.</p>
  <p>Goals:</p>
  <ol>
  <li><p>I want to extract the rows that has values of columns &quot;generation_id&quot; or &quot;is_main_series&quot; greater than 0 and assign them a variable &quot;selection&quot;
  (Just to be clear, I want rows that has at least one of two columns greater than 0.)</p>
  </li>
  <li><p>Then, I extract the &quot;identifier&quot; columns from the &quot;selection&quot; and assign them a variable &quot;name&quot;.</p>
  </li>
  <li><p>Finally, I would like to format the rows of &quot;selection&quot; for each &quot;name&quot; in this way --&gt; name(generation_id, is_main_series), name1(is_main_series), etc</p>
  </li>
  </ol>
  <p>Error:
  line 7: ValueError: Cannot index with multidimensional key</p>
  <p>I'm struggling to find solution for this error because I don't think this Dataframe is multiindexed.</p>
  <p>Here is the code I wrote so far:</p>
  <pre><code>import pandas as pd
  
  df = pd.read_csv('abilities.csv')
  df = df.fillna(0)
  
  def getPokedex():
      selection = df.loc[df[['generation_id', 'is_main_series']] != 0 ]
      for donor in selection:
          name = selection['identifier']
          name = name.to_string(index=False)
          for types in selection.columns:
              return f&quot;{name}(types)&quot;
  
  print(getPokedex())
  </code></pre>
  <p>Would appreciate any help.</p>
  <p><strong>UPDATED:</strong>
  Excel File sample:</p>
  <pre><code>TypeA1, TypeA2, TypeA3, TypeA4, TypeA5, TypeA6, TypeB, TypeC, TypeD, TypeE
  20, 0, 10, 4, 0.5, 75, 1000, 0, 2, 14
  0, 1, 1, 1, 1, 0, 23, 2, 10, 34
  </code></pre>
  <p>Code I wrote:</p>
  <pre><code>  import pandas as pd
    import numpy as np
      
      df = pd.read_excel('sample.xlsm', header=2)
      # Replace empty cells with 0
      df = df.fillna(0)
      
      # Format rows
      df['Formatted_column'] = df['Name'] + '(' + np.where(df[['TypeA1', 'TypeA2', 'TypeA3', 'TypeA4', 'TypeA5', 'TypeA6']].astype(str) !='0', 'A', '') + ',' + np.where(df['TypeB'].astype(str) !='0', 'B', '') + np.where(df['TypeC'].astype(str) !='0', 'C', '') + np.where(df['TypeD'].astype(str) !='0', 'D', '') + np.where(df['E'].astype(str) !='0', 'E', '') + ')'
      print(', '.join(df['Formatted_column'].to_list()))
  </code></pre>
  <p>My desired outcome would be james(A,C), mary(C), luke(A,B,D), etc</p>
  <p>But Python raises this error in line 8:</p>
  <pre><code>TypeError: unsupported operand type(s) for +: 'int' and 'str'
  </code></pre>