2

2 つのファイルを DataFrame としてインポートし、「新しい価格」と「12 か月の注文数量」を乗算したいと考えています。これらの 2 つの列を乗算できるようにするために、列を文字列から数値に正常に変更したと思います。そして、私は何か間違ったことをしたようです。

データ型を変更して、2 つの列を乗算し、その列を DataFrame の末尾に追加できるようにします。

次に、乗算された価格の合計を取得したいと思います。

これが失敗した私のコードです。

Comparisonfile[['New Price']].convert_objects(convert_numeric =True) Comparisonfile[['12 Month Quantity Ordered']].convert_objects(convert_numeric =True)

  Comparisonfile[['12 Month Quantity Ordered']].convert_objects(convert_numeric =True)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-69-e8d0f16b4286> in <module>()
----> 1 Comparisonfile['Proposed Ext. Price'] = Comparisonfile['New
     Price']*Comparisonfile['12 Month Quantity Ordered']

C:\Anaconda2\lib\site-packages\pandas\core\series.pyc in wrapper(self, other, name)
162             if self.index.equals(other.index):
163                 name = _maybe_match_name(self, other)
--> 164                 return Series(wrap_results(na_op(lvalues, rvalues)),
165                               index=self.index, name=name, dtype=dtype)
166 

C:\Anaconda2\lib\site-packages\pandas\core\series.pyc in na_op(x, y)
 72             if isinstance(y, pa.Array):
 73                 mask = notnull(x) & notnull(y)
---> 74                 result[mask] = op(x[mask], y[mask])
 75             else:
 76                 mask = notnull(x)

 TypeError: can't multiply sequence by non-int of type 'float'

列の値を変更したと思いました...

4

1 に答える 1