gpt4 book ai didi

python - pd.DataFrame.boxplot 与 pd.cut 不兼容

转载 作者:行者123 更新时间:2023-11-28 22:37:42 29 4
gpt4 key购买 nike

示例代码:

import pandas as pd
import numpy as np
sample = pd.DataFrame({"a":[1,2,3,1,2,3,1,2,3], "b":np.random.uniform(0,1,9)})

sample.boxplot(column="b", by=pd.cut(sample.a, bins=2))

plot

除了箱形图图片,一些文本出现在图的周围。如何从图中删除文本?

最佳答案

您可以尝试通过cut 创建新列c ,因为在 DataFrame.boxplot参数 by 可以是 column:

by : string or sequence

Column in the DataFrame to group by

import pandas as pd
import numpy as np

sample = pd.DataFrame({"a":[1,2,3,1,2,3,1,2,3], "b":np.random.uniform(0,1,9)})

sample['c'] = pd.cut(sample.a, bins=2)
sample.boxplot(column="b", by='c')

enter image description here

关于python - pd.DataFrame.boxplot 与 pd.cut 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36286140/

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