如何转换带双反斜杠的字符串行:
myColumn =
['hot\\gas\\substance\\1',
'hot\\gas\\substance\\2',
'hot\\gas\\substance\\3']
成排带单个反斜杠的字符串:
myColumn=
['hot\gas\substance\1',
'hot\gas\substance\2',
'hot\gas\substance\3']
并将myColumn另存为csv:
myColumn.to_csv(exportPath +'/myColumnNEW.csv', index=False)
谢谢
注意 如果我将myColumn保存在.csv中并用Excel打开它,我会在列中看到双反斜杠: here is the screenshot of output
试试
myColumn = [s.replace('\\\\', '\\') for s in myColumn]
。这应该将双反斜杠(4个反斜杠文字)替换为单反斜杠(2个反斜杠文字)给定的
代码
或者,使用^{} 模块:
输出
相关问题 更多 >
编程相关推荐