Amelio Vazquez-Reina - 6 months ago 53

Python Question

I am unable to find the entry on the method

`dot()`

On this topic, is there a way compute an element-wise multiplication of every row in a data frame with another vector? (and obtain a

`dataframe`

`dot()`

Answer

Here is an example of how to multiply a DataFrame by a vector:

```
In [60]: df = pd.DataFrame({'A': [1., 1., 1., 2., 2., 2.], 'B': np.arange(1., 7.)})
In [61]: vector = np.array([2,2,2,3,3,3])
In [62]: df.mul(vector, axis=0)
Out[62]:
A B
0 2 2
1 2 4
2 2 6
3 6 12
4 6 15
5 6 18
```

Source (Stackoverflow)