如何将列的值替换为箱值的平均值?

发布于 2025-01-11 18:49:36 字数 608 浏览 7 评论 0原文

给定以下 DataFrame 列:

0    -0.0985
 1    -0.0880
 2    -0.1068
 3    -0.2338
 4    -0.2807
 5    -0.1570
 6    -0.2043
 7    -0.0776
 8    -0.1572
 9    -0.0501
 10   -0.0926
 11   -0.2075
 Name: 2, dtype: float64)

以及 pandas.qcut 分类和 bin:

(0     bin_2
 1     bin_3
 2     bin_2
 3     bin_0
 4     bin_0
 5     bin_1
 6     bin_1
 7     bin_3
 8     bin_1
 9     bin_3
 10    bin_2
 11    bin_0
 Name: 2, dtype: category
 Categories (4, object): ['bin_0' < 'bin_1' < 'bin_2' < 'bin_3']

如何创建具有相同大小的列,并将每个值替换为 bin 中值的平均值?

Given the below DataFrame column:

0    -0.0985
 1    -0.0880
 2    -0.1068
 3    -0.2338
 4    -0.2807
 5    -0.1570
 6    -0.2043
 7    -0.0776
 8    -0.1572
 9    -0.0501
 10   -0.0926
 11   -0.2075
 Name: 2, dtype: float64)

and the pandas.qcut categorical and bins:

(0     bin_2
 1     bin_3
 2     bin_2
 3     bin_0
 4     bin_0
 5     bin_1
 6     bin_1
 7     bin_3
 8     bin_1
 9     bin_3
 10    bin_2
 11    bin_0
 Name: 2, dtype: category
 Categories (4, object): ['bin_0' < 'bin_1' < 'bin_2' < 'bin_3']

How to create a column with the same size, and replace each value by the mean of the values in the bin?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文