I have two multiIndex dataframes; 1 indicating which player is on server, the other keeps track of the points. Hereby the serving player rotates every game.
col0 = ['Game 1','Game 1','Game 2','Game 2','Game 3','Game 3','Game 4','Game 4','Game 5','Game 5']
col1 = ['P1','P2','P1','P2','P1','P2','P1','P2','P1','P2']
a = pd.DataFrame(data = np.random.rand(3,10))
a.columns = [col0,col1]
Game 1 Game 2 ... Game 4 Game 5
P1 P2 P1 ... P2 P1 P2
0 0.375562 0.408865 0.107393 ... 0.552553 0.986619 0.635726
1 0.101053 0.949870 0.804260 ... 0.895951 0.384401 0.368055
2 0.879938 0.740631 0.369314 ... 0.624967 0.061308 0.625157
and dataframe 'b' indicating which player is on serve.
col0 = ['Game 1','Game 2','Game 3','Game 4','Game 5']
col1 = ['Server','Server','Server','Server','Server']
b = pd.DataFrame([[1,2,1,2,1],
[2,1,2,1,2],
[1,2,1,2,1]])
b.columns = [col0, col1]
Game 1 Game 2 Game 3 Game 4 Game 5
Server Server Server Server Server
0 1 2 1 2 1
1 2 1 2 1 2
2 1 2 1 2 1
Now I want to create dataframe c, that looks like:
Game 1 Game 2 ... Game 4 Game 5
P1 P2 P1 ... P2 P1 P2
0 0.375562 0.408865 np.nan ... np.nan 0.986619 0.635726
1 np.nan np.nan 0.804260 ... 0.895951 np.nan np.nan
2 0.879938 0.740631 np.nan ... np.nan 0.061308 0.625157
I want the values of dataframe 'a' to be replaced by NaN's whenever player 2 is on serve. In the first row for example of dataframe 'c' only the points in game 1, game 3 and game 5 are shown, since player 1 is on serve in those games.
Anything would help!