我需要将反斜杠替换为其他内容,并编写以下代码来测试基本概念。工作正常:
test_string = str('19631 location android location you enter an area enable quick action honeywell singl\dzone thermostat environment control and monitoring')
print(test_string)
test_string = test_string.replace('singl\\dzone ','singl_dbl_zone ')
print(test_string)
19631 location android location you enter an area enable quick action honeywell singl\dzone thermostat environment control and monitoring
19631 location android location you enter an area enable quick action honeywell singl_dbl_zone thermostat environment control and monitoring
但是,我有一个熊猫df充满了这些(重新配置)字符串,当我试图操作df时,它不起作用。在
^{pr2}$反斜杠仍然存在!在
323096 you enter an area android location location environment control and monitoring honeywell singl\dzone thermostat enable quick action
str.replace
和{使用
str.replace
,您需要传递一个原始字符串。在我认为去掉反斜杠会更容易:
相关问题 更多 >
编程相关推荐