pandas 数据框乘以一系列 [英] pandas dataframe multiply with a series

查看:162
本文介绍了 pandas 数据框乘以一系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过存储在系列 DataFrame 的所有列乘以最佳方法是什么? >?我曾经在Matlab中这样做,而$ P code $ repmat(),这在熊猫中不存在。我可以使用 np.tile(),但是每次都来回转换数据结构看起来很丑。

What is the best way to multiply all the columns of a Pandas DataFrame by a column vector stored in a Series? I used to do this in Matlab with repmat(), which doesn't exist in Pandas. I can use np.tile(), but it looks ugly to convert the data structure back and forth each time.

谢谢。

推荐答案

result = dataframe.mul(series, axis=0)

http://pandas.pydata.org/pandas-docs/stable/basics.html#flexible-binary-operations

这篇关于 pandas 数据框乘以一系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆