Q:

Stacking the dataframes and ranking

Can't quite find what I need in the questions, please correct me if I'm wrong.  I have a number of dfs that are similar in shape and which may contain nans.  Suppose a df that does not contain the nans looks like this:
np.random.seed(1)
mat = lambda: np.random.normal(size=10).reshape((5, 2))
df1 = pd. DataFrame(mat())
df2 = pd. DataFrame(mat())
df3 = pd. DataFrame(mat())

I want to somehow stack the df1, df2 and df3 on top of each other.  And then rank each value across the df1, df2, df3 (i.e. the stack levels). 
So the individual dfs, in this case will look like:
df1

df2

df3

So in this case in the ".iloc[0, 0]" we have the values: 1.62, 1.46 and -1.1, so the ranked df1 would have value 3, df2 would have value 2 and df3 would have value 1.  And then this ranking is performed for each value across the dataframe levels.  The general case will have about 16 dataframes stacked on top of each other and only 5 ranks, when there are nans, the df gets a rank of 0. 

A:

I think you need concat with GroupBy.rank:
df1.loc[0,1] = np.nan

df = pd.concat([df1, df2, df3], keys=('df1','df2','df3')).groupby(level=1).rank().fillna(0)
print (df)
         0    1
df1 0  3.0  0.0
    1  1.0  1.0
    2  1.0  1.0
    3  3.0  3.0
    4  3.0  1.0
df2 0  2.0  1.0
    1  2.0  2.0
    2  3.0  2.0
    3  1.0  2.0
    4  2.0  3.0
df3 0  1.0  2.0
    1  3.0  3.0
    2  2.0  3.0
    3  2.0  1.0
    4  1.0  2.0

