I have a pandas dataframe full of data
import pandas as pd
import numpy as np
varNames = ["point1","point2","point3","point4","point5"]
df = pd.DataFrame(np.random.randn(5,2),index=varNames,columns=["data1","data2"])
and I would like to create a series with a multiIndex created from this. The index I can do:
iterables=[["point1","point2","point3"],["point4","point5"]]
index=pd.MultiIndex.from_product(iterables, names=['numerator', 'denominator'])
I don't know how to fill the series though. I'm after something like
s = pd.Series(max(df.loc[index["numerator"]]/df.loc[index["denominator"]]),index=index)
I want to take each row in the first dataframe that's listed as a numerator, and divide it by each row in the first dataframe that's listed a denominator, find the maximum value from the resulting line of values and store it in the relevant place (s[variableN,variableM]) in the series.
This is my first time using this multi-index thing, and short of going through the series line by line, working out the value and storing it, similar (I think, I don't think I've been able to fully understand this yet) this, I can't figure out how to do this.