Brian Brian - 7 months ago 30
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

pandas DataFrame's also have a dot method.

Just do this:

df.dot(df)
Comments