对dataframe中每个元素进行同样的函数操作,且函数不止一个输入
发布日期:2021-06-29 03:49:09 浏览次数:3 分类:技术文章

本文共 329 字,大约阅读时间需要 1 分钟。

import numpy as npimport pandas as pd df = pd.DataFrame([[0.01,0.01],[0.2,0.2]])# df#       0     1# 0  0.01  0.01# 1  0.20  0.20 def binarization(x, threshold, pos=1, neg=0):    if x >= threshold:        return pos    else:        return neg df = df.apply(np.vectorize(binarization),args=(0.1,))  # df#    0  1# 0  0  0# 1  1  1

转载地址:https://blog.csdn.net/zdx1996/article/details/108406397 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:程序员提升工作效率和质量小技巧(偏算法工程师)
下一篇:python 自定义向量化(vectorized)操作函数

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月03日 09时38分58秒