Brian Brian - 2 years ago 175
Python Question

matrix math using pandas

I have a

DataFrame
that I'd like to perform matrix multiplication with. Can pandas do that?

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.rand(5, 5))


I don't want to have to do this:

df.values.dot(df.values)

Answer Source

pandas DataFrame's also have a dot method.

Just do this:

df.dot(df)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download