ng khanh
ng khanh

Reputation: 71

find max in each cell of multiple DataFrame Pandas

I have about 2000 similar DataFrames (DF1,DF2,....,DF2000) with same shape ( names of columns and index).
I want to get max and min values in each cells (same positions). I could iterate by column names and index to verify but it would be very slow. What's the best way to do such task ?
Example:

columns = ['A','B','C','D']
for i in range(4):
    pd.DataFrame(np.random.randint(100, size=(4, 4)),columns=columns) 

4 similar DF
I need max values DF with

DF_max[0,'A] = 78

and min values DF with

DF_min[0,'A'] = 10

Upvotes: 3

Views: 2375

Answers (1)

BENY
BENY

Reputation: 323326

Assuming you have all the df in a list

l=[df1,df2,df3.....]

DF=pd.concat(l,keys=range(len(l))).groupby(level=1)

maxdf=DF.max()
mindf=DF.min()

Upvotes: 4

Related Questions