gpt4 book ai didi

Python - 模式插补 - 将一列的模式应用到另一列

转载 作者:太空宇宙 更新时间:2023-11-04 00:34:26 25 4
gpt4 key购买 nike

我需要在 Python 中进行必要的插补:

enter image description here

我尝试使用:

 # Outlet_Size - Imputation - Its Not Running need to check Version 2.X
#Import mode function:
from scipy.stats import mode

#Determing the mode for each
outlet_size_mode = data.pivot_table(values='Outlet_Size',
columns='Outlet_Type',aggfunc=(lambda x:mode(x).mode[0]))

但我在创建数据透视表时遇到错误,我使用的是 Python 3.X 最新版本。

还在寻找其他选择吗?

最佳答案

我相信你可以使用 Series.mode并为选择第一个值添加 Series.iat :

outlet_size_mode = data.pivot_table(values='Outlet_Size',
columns='Outlet_Type',
aggfunc=lambda x: x.mode().iat[0])
print (outlet_size_mode)
Outlet_Type Supermarket_Type2 Supermarket_Typel
Outlet_Size Small Medium

关于Python - 模式插补 - 将一列的模式应用到另一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44692923/

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