title: Transpose Pandas dataframe but keep only nonzero values
body: <p><strong>DataFrame:</strong></p>
  
  <p>Let me clarify my question. My <code>pandas.DataFrame</code> looks like this  </p>
  
  <pre><code>data = [
      ['word11', 'word12', 'word13', 'word14', 0, 0, 0, 0, 0],
      ['word21', 'word22', 'word23', 'word24', 0, -3, 34, 0, 0],
      ['word31', 'word32', 'word33', 'word34', 0, 1.6, 0, 0, 0],
      ['word41', 'word42', 'word43', 'word44', 0, 0, 0, 0, 0]
  ]
  
  df = pd.DataFrame(data, columns=['word1', 'word2', 'word3', 'word4', 'C1', 'C2', 'C3', 'C4', 'C5'])
  </code></pre>
  
  <p><strong>Output to be generated:</strong></p>
  
  <p>From this, I want to get a data frame which looks like </p>
  
  <pre><code>    word1   word2   word3   word4  C1   C2  C3  C4  C5
  0  word11  word12  word13  word14   0  0.0   0   0   0
  1  word21  word22  word23  word24   0 -3.0  34   0   0
  2  word31  word32  word33  word34   0  1.6   0   0   0
  3  word41  word42  word43  word44   0  0.0   0   0   0
  </code></pre>
  
  <p><strong>My Program:</strong></p>
  
  <p>Here is what I did to get the above data frame </p>
  
  <pre><code>primary_columns = ['word1', 'word2', 'word3', 'word4']
  transposing_columns = ['C1', 'C2', 'C3', 'C4', 'C5']
  transposed_df = df.melt(id_vars=primary_columns, value_vars=transposing_columns)
  compare_columns = primary_columns + ['value']
  </code></pre>
  
  <p>Then I divided the data frame into two based on the value of 'value' column and dropped duplicates. </p>
  
  <pre><code>nonzero_df = transposed_df[transposed_df['value'] != 0]
  zero_df = transposed_df[transposed_df['value'] == 0]
  zero_df = zero_df.drop_duplicates(subset=compare_columns, keep='first')
  df = nonzero_df.append(zero_df)
  </code></pre>
  
  <p>Which gives me the following output</p>
  
  <pre><code>df = df.reset_index(drop=True)
  df
  
      word1   word2   word3   word4 variable  value
  0  word21  word22  word23  word24       C2   -3.0
  1  word31  word32  word33  word34       C2    1.6
  2  word21  word22  word23  word24       C3   34.0
  3  word11  word12  word13  word14       C1    0.0
  4  word21  word22  word23  word24       C1    0.0
  5  word31  word32  word33  word34       C1    0.0
  6  word41  word42  word43  word44       C1    0.0
  </code></pre>
  
  <p><strong>Issue:</strong></p>
  
  <p>I don't want to see <code>df.iloc[4]</code> and <code>df.iloc[5]</code>. </p>
  
  <p>If the values of <code>word1</code>, <code>word2</code>, <code>word3</code> and  <code>word4</code> are the same but the difference is only in the <code>value</code> column, keep the row with non-zero value and drop the row with 0 value. I don't care about the value of the column <code>variable</code>. </p>
  
  <p>How can I achieve this? </p>
  
  <p><strong>NOTE:</strong></p>
  
  <ol>
  <li>My data frame is huge. It contains close to million rows more than 15  <code>Word*</code> type columns and more than 115  <code>C*</code> type columns(<code>word*</code> and <code>C*</code> are the column names I used for my example).</li>
  <li>I use <code>Python 2.7</code> with <code>Pandas 0.17</code>.</li>
  </ol>