【发布时间】:2017-03-04 12:54:55
【问题描述】:
我有两个 DataFrame 对象,我想在每一行上应用逐元素乘法:
df_prob_wc.shape # (3505, 13)
df_prob_c.shape # (13, 1)
我想我可以用DataFrame.apply() 做到这一点
df_prob_wc.apply(lambda x: x.multiply(df_prob_c), axis=1)
这给了我:
TypeError: ("'int' object is not iterable", 'occurred at index $')
或与
df_prob_wc.apply(lambda x: x * df_prob_c, axis=1)
这给了我:
TypeError: 'int' object is not iterable
但它不起作用。 但是,我可以这样做:
df_prob_wc.apply(lambda x: x * np.asarray([1,2,3,4,5,6,7,8,9,10,11,12,13]), axis=1)
我在这里做错了什么?
【问题讨论】:
标签: pandas dataframe series multiplication elementwise-operations