Python笔记:用正则表达式把前缀或后缀的一个字母替换成其它词

Python笔记:用正则表达式把前缀或后缀的一个字母替换成其它词,第1张

Python笔记:用正则表达式把前缀或后缀的一个字母替换成其它词

示例一:

import pandas as pd
x = pd.Dataframe({"序号":range(1,6),
                  "水果":["A产品", "苹果", "B产品", "西瓜", "香蕉"],
                  "蔬菜":["白菜", "C产品", "土豆", "D产品", "冬瓜"],
                  "水产":["河虾", "E产品", "F产品", "草鱼", "鲜蚝"],
                  "禽类":[ "鸡蛋", "鸭蛋", "G产品", "鹅蛋", "H广东产品"]})
x


解题:

y = x.replace(r"[A-Z]", "优秀的", regex = True)
y

示例二:

import pandas as pd
x1 = pd.Dataframe({"序号":range(1,6),
                  "水果":["产品A", "苹果", "产品B", "西瓜", "香蕉"],
                  "蔬菜":["白菜", "产品C", "土豆", "产品D", "冬瓜"],
                  "水产":["河虾", "产品E", "产品F", "草鱼", "鲜蚝"],
                  "禽类":[ "鸡蛋", "鸭蛋", "产品G", "鹅蛋", "广东产品H"]})
x1


解题:

y1 = x1.replace(r"[A-Z]", "好用", regex = True)
y1



交互式可视化大屏的概念

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5495605.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存