python - Pandas 使用搜索字符串更新列
问题描述
您好,我正在使用 pandas 练习,我正在尝试弄清楚如何在匹配“费用”时将类别字段设置为费用。我尝试了一种无效的掩蔽技术。谢谢
df = g1_2019[g1_2019['Description'].str.contains('Fee')]
df.head()
Index Date No. Description Category
495 3/18/2019 0 Withdrawal RW-ISA:Fee: International Service Fee Not Categorized
496 3/18/2019 0 International Service Fee Assessed = $0.07 on ... Not Categorized
650 4/17/2019 0 Withdrawal RW-ISA:Fee: International Service Fee Not Categorized
651 4/17/2019 0 International Service Fee Assessed = $0.07 on ... Not Categorized
879 5/17/2019 0 Withdrawal RW-ISA:Fee: International Service Fee Not Categorized
解决方案
尝试:
mask = g1_2019['Description'].str.contains('Fee')
g1_2019.loc[mask, "Category"] = "Fees"
推荐阅读
- arm - ARMv6M ADD(register) T2 Encoding 规范中的“DN”是什么?
- c# - 从网站上抓取的字符串有 ' ' 输出为 '?'
- sql - 如何添加带整数的日期
- javascript - SyntaxError:位置 2 处 JSON 中的意外标记 v
- typo3 - tx_news 翻译中的错误内容元素
- javascript - Chrome 扩展程序(页面上的内容脚本)是否可以访问 TINYMCE 编辑器中的光标位置?
- omnet++ - 如何在 omnet++ 中记录结果
- rust - 获取下一个后遍历一个链接结构释放锁
- bash - 如何重定向管道awk脚本
- java - 从 spring-boot-starter-web 中排除 Logback 依赖项会阻止 log4j 系统正确初始化