title: pandas series bits to integer in decimal base
body: <p>I have a pandas Dataframe of dimensions (<code>m</code>,<code>n</code>) that is filled with <code>0</code> and <code>1</code>. 
  If each row of the dataframe is considered as a binary number, I would like to generate a pandas Series with the integer number in base 10 represented by that row.</p>
  
  <p>Given the following matrix of dimensions (<code>m</code>,<code>n</code>) filled with <code>0</code> and <code>1</code>:</p>
  
  <pre><code>m = int(1e6)
  n = 5
  df = pd.DataFrame(np.random.rand(m,n)).round().astype(int)
  </code></pre>
  
  <p>The method I use right now is this one:</p>
  
  <pre><code>df_asstr = df.astype(str)
  bin_series = df_asstr.sum(axis=1).astype(int).astype(str)
  
  def bin_to_int(strnum):
      return int(strnum, 2)
  
  decimal_series = bin_series.astype(str).apply(bin_to_int)
  </code></pre>
  
  <p>My issue here is TIMING. If the dataframe has length on the order of <code>m=1e3</code>, then the whole process takes less than one second. However, when I with <code>m=1e6</code>, it takes about 22 seconds, and I need to run many of these, so I really want to speed it up.</p>
  
  <p>I am aware that the steps slowing down the process are those involving conversion of the <code>DataFrame</code> to <code>str</code>, i.e. these lines: </p>
  
  <pre><code>df_asstr = df.astype(str)
  bin_series = df_asstr.sum(axis=1).astype(int).astype(str)
  decimal_series = bin_series.astype(str).apply(bin_to_int)
  </code></pre>
  
  <p>Does anyone know a more efficient way to create the series of integers in decimal base?? Thanks a lot!</p>