gpt4 book ai didi

python - 在 jupyter notebook 中水平打印 Quantile 函数的输出

转载 作者:行者123 更新时间:2023-11-28 17:03:58 26 4
gpt4 key购买 nike

我正在运行此代码以在 python 3 中生成分位数,但它会垂直打印输出。是否可以水平打印输出

import numpy as np
import pandas as pd

r = np.random.random_sample((5,))
pd.Series(r).quantile(q = np.linspace(0,1,11))

0.0 0.112624
0.1 0.261145
0.2 0.409665
0.3 0.531582
0.4 0.626897
0.5 0.722211
0.6 0.746804
0.7 0.771397
0.8 0.818495
0.9 0.888097
1.0 0.957699
dtype: float64

我希望输出是这样的

0.0         0.1         0.2         ...
0.112624 0.261145 0.409665 ...
dtype: float64

最佳答案

您可以将其转换为 DataFrame 并使用转置 df.T:

import numpy as np
import pandas as pd

r = np.random.random_sample((5,))
df = pd.DataFrame(r).quantile(q = np.linspace(0,1,11))

print(df.T)

关于python - 在 jupyter notebook 中水平打印 Quantile 函数的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52453840/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com