考虑dict
dfs
这是一本字典pd.DataFrame
s
import pandas as pd
import numpy as np
np.random.seed([3,1415])
dfs = dict(
one=pd.DataFrame(np.random.randint(1, 10, (5, 5))),
two=pd.DataFrame(np.random.randint(1, 10, (5, 5))),
three=pd.DataFrame(np.random.randint(1, 10, (5, 5))),
)
处理这个问题的最好方法是使用pd.Panel
对象,这是类似于的更高维对象pd.DataFrame
.
p = pd.Panel(dfs)
那么你需要的答案就非常简单
max
p.max(axis='items')
or p.max(0)
倒数第二个
p.apply(lambda x: np.sort(x)[-2], axis=0)