TypeError: can't multiply sequence by non-int of type 'float' even after using np.multiply
<p>I have the following which works along the rows of a dataframe. I have
tried many things, like <code>np.multiply</code> or <code>np.array</code> to make that
multiplication works but so far to no avail. I have also converted
factor to an <code>int</code> by multiplying and then dividing it by 10, but
nothing either. I have wrapped all my operands individually into
<code>np.array()</code>, and also have tried to <code>np.multiply</code> around every single
operation, but I still get that error.</p>

<pre><code>factor = somefloatnumber  # i.e 0.4
def func(row): 
   return row *factor / np.sum(row)   
df2 =  df1.apply(func, axis=1)  
</code></pre>

<blockquote>
  <p>TypeError: can't multiply sequence by non-int of type 'float'</p>
</blockquote>

<p>Here is a sample of the data I am using.          </p>

<pre><code>                    A       B          C         D         E
2006-04-28 A       69.62     69.62    3.518     65.09     69.62
           B       27.78    7.7       27.78      27.7       27
           C        0.23     0.22     0.02      0.23      0.21

2006-05-01 A       71.5      71.5      6.522     65.16      71.5
           B      28.4828   28.4828    28.4828   28.4828   28.4828
           C      0.249841  0.249841  0.0227897  0.227687  0.249841
</code></pre>

<p>It seems that 
<code>convert_objects(convert_numeric=True)</code> has done the trick!<br>
 It attempts to infer better dtype for object columns
 see:                                                      <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.convert_objects.html" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.convert_objects.html</a></p>

<p>In the case of my issue above, you would use it this way</p>

<pre><code>df1.convert_objects(convert_numeric=True).apply(func,axis=1).
</code></pre>

<p>However, i get a Future warning:</p>

<blockquote>
  <p>FutureWarning: convert_objects is deprecated.  Use the data-type
  specific converters pd.to_datetime, pd.to_timedelta and pd.to_numeric.</p>
</blockquote>

<p>But it works.</p>

python arrays pandas numpy casting