user40780
user40780

Reputation: 1930

perform linear algebra operation with pandas data frame

Suppose I have 2 pandas series, which I perceive as column vector in linear algebra x1 and x2

I want to do the operation x1 * x2^T, which is a column vector multiply with a row vector to produce a matrix (pandas dataframe).

What is the best procedure for this?

Upvotes: 0

Views: 2031

Answers (2)

davidshere
davidshere

Reputation: 396

You want to import numpy and call:

pandas.DataFrame(numpy.outer(x1, x2))

Upvotes: 2

erocoar
erocoar

Reputation: 5913

Inside of pandas, you can go back to data frames to do it, e.g.

x1.to_frame().dot(x2.to_frame().T)

Upvotes: 1

Related Questions