我已将两个文件作为 DataFrames 导入,并希望将“新价格”乘以“12 个月订购数量”。我虽然已经成功地将列从字符串更改为数字,以便能够将这两列相乘。看来我做错了什么。
我想更改数据类型,以便可以将两列相乘,然后将这两列添加到 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'
我以为我已经改变了列的值......