tbd33南3
我试图用游戏平台和类型的平均user_score替换user_score。这是我的代码:
dft = new_df.query('user_score != "tbd" & user_score.isnull()')
df_typical_user_ratio_by_platform = dft.groupby(['platform', 'genre'])['user_score'].apply(lambda x: x.sample(1).iloc[0])
def correct_user_score(row):
platform = row['platform']
genre = row['genre']
if (row['user_score'] == 'tbd' or pd.isnull(row['user_score']) or row['user_score']=='nan'):
u = df_typical_user_ratio_by_platform.loc[[platform, genre]].head(1).astype('float')
uScore = ", ".join(map(str, u))
else:
uScore = row['user_score']
return uScore
row = pd.Series(data=row_values, index=['user_score', 'platform', 'genre'])
correct_user_score(row)
new_df['user_score'] = new_df.apply(correct_user_score, axis=1)
new_df.sample(40)
# df['user_score'] = df['user_score'].astype('int')
这是结果。User_score目前是一个对象。我不知道该怎么取代南。我试着做if u = 'nan',但那不起作用。任何建议吗?
https://i.stack.imgur.com/g7AU4.jpg
- 强制无效值到NaN与
to_numerice()
fillna()
与计算您想要的
s = 20
df = pd.DataFrame({"userid":np.random.randint(1,5,s),
"platform":np.random.choice(["windows","macos","ios","android"],s),
"userscore":np.random.randint(1,10,s)})
# let's splat some scores...
df = df.assign(userscore=np.select([(df.userscore==7)&(df.index<10),(df.userscore==6)&(df.index<10)],["tbd",np.nan],df.userscore))
df["bad"] = df.userscore
df = df.assign(userscore=pd.to_numeric(df.userscore, errors="coerce"))
df.userscore = df.userscore.fillna(df.groupby(["userid","platform"])["userscore"].transform("mean"))
输出相关内容
- 将0值替换为r中的行平均值
- r语言 - 如何将 NA 替换为数字列的平均值和按组划分的字符列的模式值?
- 如何在R的一行中找到重复的日期,然后用平均值替换相关值?
- R:将列(NA和values)中的所有值替换为值的平均值
- 将组中的Outlier替换为pandas系列中该组的平均值
- 如何应用类函数来替换NaN为熊猫df列的子集内的平均值?
- 当平均值高于另一个列表中的同一项时,将列表中的None替换为最近3个非None项的平均值
- 如何将NULL值替换为SQL中一个类别的平均值?
- 用平均值替换特定列
- 将数组中的元素替换为它们的平均值
- 用数据框架Julia中每列的平均值替换缺失值
- r语言 - 如何使用聚类组的平均值替换数据集中的NA
- 将分组列的异常值替换为基于定义的 zscore 的组平均值
- 将NA值替换为r中前后行值的平均值
- 用r中的平均值替换离群值时的问题
- Pandas将column的所有值替换为仅一组的平均值
- 将na替换为时间序列r中特定日期的平均值
- 取范围实体的平均值,并将其替换为pandas列
- 用Teradata中按连接类别分组的值的平均值替换空值
- 如何替换数据框架列有?符号的列的平均值在spark scala?
最新更新
- 检查数据库列是否包含、以 EF 查询的 where 子句中的任何列表项开头或结尾不起作用
- 如果表单内的任何按钮被点击,Angular表单字段就会被验证
- c语言 - 我无法更新文本文件中的新数据
- Podman push not verbose and VM out of sync
- 不知道我使用的是Firebase JS SDK还是React-Native-Firebase
- 如何计数列表出现与Data.Map?
- JavaScript Promise .then(onFulfilled, onRejected) vs. .then(
- Kubernetes emptyDir and symlinks
- 如何在micronaut声明性客户机中接收空响应?
- Cloudflare和本地网站显示mailchimp不同?
- 如何在android中存储硬编码加密主密钥?
- 如何提示用户在手机上注册生物识别
- 在哪里可以找到Databricks中的spark日志
- Solidgauge标签和图例不反映系列颜色
- 随机登陆页(Vue / Javascript)
- 如何在GitLab CI作业中使用docker构建缓存?
- CDK Pipeline - Trigger Step Function
- 一种在Python中使可执行文件仅在特定时间内工作的方法
- 如何在启动GCP VM实例时使用自定义python命令调度该实例?
- 图像消失时,我选择一个文件与Flet Python
- 是否有一种方法允许CORS处理飞行前响应的自定义标头
- OSError: [Errno 57] Socket is not connected (python macos中的S
- 使用lag()或类似的方法,具有开始值和结束值的帐户滚动
- 我如何重写子类中重写超类的函数依次(Python)?
- 无法使用WooCommerce API将产品添加到相应的类别/子类别
- 用户登录到应用程序注册时Azure AD管理员同意错误
- Unity 3d:在不知道我将使用的确切预制的情况下,我如何在运行时启动预制?
- c -构建简单shell时文件重定向的问题
- AWS Lambda实际上记录到控制台以外的任何本地接收器(因此是CloudWatch)吗?
- 我如何在Django中为mymyy输入一个自定义用户模型管理器?
热门标签:
javascript python java c# php android html jquery c++ css ios sql mysql arrays asp.net json python-3.x ruby-on-rails .net sql-server django objective-c excel regex ruby linux ajax iphone xml vba spring asp.net-mvc database wordpress string postgresql wpf windows xcode bash git oracle list vb.net multithreading eclipse algorithm macos powershell visual-studio image forms numpy scala function api selenium