【问题标题】:pd.DataFrame(np.random.randn(8, 4), index=dates, columns=['A', 'B', 'C', 'D'])pd.DataFrame(np.random.randn(8, 4), index=dates, columns=['A', 'B', 'C', 'D'])
【发布时间】:2018-11-01 02:17:47
【问题描述】:

如果有人可以解释一下吗?我如何获得这些十进制值以及 np.random.randn(6,4) 的含义是什么?

In [8]: df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=list('ABCD'))

In [9]: df
Out[9]: 
                   A         B         C         D
2013-01-01  0.469112 -0.282863 -1.509059 -1.135632
2013-01-02  1.212112 -0.173215  0.119209 -1.044236
2013-01-03 -0.861849 -2.104569 -0.494929  1.071804
2013-01-04  0.721555 -0.706771 -1.039575  0.271860
2013-01-05 -0.424972  0.567020  0.276232 -1.087401
2013-01-06 -0.673690  0.113648 -1.478427  0.524988

【问题讨论】:

  • 第一个问题:你读过docs吗?第二个问题:您了解文档吗?

标签: python pandas dataframe


【解决方案1】:

基本上np.random.randn 返回均值 = 0 和方差 = 1 的正态分布的随机浮点值。现在 np.random.randn 成形,您希望返回这些分布。

例如:

np.random.randn(1,2) 返回一行两列的数组。同样,您可以提供np.random.randn(1,.,.,.,9),它会为您提供一个复杂的数组。由于您提到了np.random.randn(6, 4),它返回了 6 行和 4 个不同的列。

有关文档,请参阅:Check this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-27
    • 1970-01-01
    • 2018-09-14
    • 2011-06-13
    • 1970-01-01
    相关资源
    最近更新 更多