python - 如何从python中的total_amount、qty和rate列中删除-ve符号

标签 python python-3.x python-2.7

transaction_id  cust_id tran_date   prod_subcat_code    prod_cat_code   Qty Rate    Tax total_amt   Store_type
0   80712190438 270351  28-02-2014  1                          1          -5    -772    405.300 -4265.300   e-Shop
1   29258453508 270384  27-02-2014  5                          3          -5    -1497   785.925 -8270.925   e-Shop
2   51750724947 273420  24-02-2014  6                          5          -2    -791    166.110 -1748.110   TeleShop
3   93274880719 271509  24-02-2014  11                         6           -3   -1363   429.345 -4518.345   e-Shop
4   51750724947 273420  23-02-2014  6                          5           -2   -791    166.110 -1748.110   TeleShop
如何从每列中删除 -ve 符号

最佳答案

这能解决你的问题吗?

df[['Qty', 'Rate', 'Tax', 'total_amt']].apply(abs)
这里我使用的是内置的 abs (数字的绝对值)将负数转换为正数。
希望这对您有用并解决您的问题!
快乐编码!

关于python - 如何从python中的total_amount、qty和rate列中删除-ve符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65261935/

相关文章:

python - 将双端队列字典减少为单个 bool 值

python - 如何清理正则表达式

python - 初学者 : How to configure my python interpreter to use the correct path to get the right version of python?

python - 如何使用 BeautifulSoup4 为 xml 标记指定命名空间?

bash - 在 shell 脚本中处理 python 返回的退出代码

Python/Django REST API 架构

python - 将图像和标签列表转换为 np 数组以训练 tensorflow

python - 在 Python 列表中存储 Python 对象与固定长度的 Numpy 数组

Django __str__ 返回非字符串(类型 NoneType)

python - ImportError : Entry point ('console_scripts' , 'easy_install' ) 未找到