用Python编写程序以根据数据框字典创建面板并打印第一列的最大值

面板中第一列的最大值的结果是

maximum value of first column is ;
Column1 1.377292

解决方案

为了解决这个问题,我们将遵循以下方法-

  • 将数据值设置为字典键是'Column1',其值作为pd.DataFrame(np.random.randn(5,3))

data = {'Column1' : pd.DataFrame(np.random.randn(5, 3))}

  • 将数据分配给面板并将其另存为p

p = pd.Panel(data)

  • 使用字典键Column1打印列

print(p['Column1'])

  • 使用minor_xs计算第一列的最大值,

p.minor_xs(0).max()

例子

让我们看下面的代码以获得更好的理解-

import pandas as pd
import numpy as np
data = {'Column1' : pd.DataFrame(np.random.randn(5, 3))}
p = pd.Panel(data)
print("Panel values:")
print(p['Column1'])
print("maximum value of first column is:")
print(p.minor_xs(0).max())

输出

Panel values:
      0          1       2
0 0.914209  -0.665899 -0.703097
1 -1.375634 -0.164529 -0.673326
2 1.377292   0.692793  0.390777
3 -0.899618 -1.163681  0.954463
4  0.025898  0.832265  0.173535
maximum value of first column is:
Column1    1.377292
dtype: float64

猜你喜欢