鱼C论坛

 找回密码
 立即注册
查看: 1711|回复: 1

[已解决]如何去掉列表项目中出现的空格,请大师帮忙

[复制链接]
发表于 2023-3-28 00:07:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
r = [["000001","HXCZHH","华夏成长混合","混合型-灵活","HUAXIACHENGZHANGHUNHE"],["000002","HXCZHH","华夏成长混合(后端)","混合型-灵活","HUAXIACHENGZHANGHUNHE"],["000003","ZHKZZZQA","中海可转债债
券A","债券型-可转债","ZHONGHAIKEZHUANZHAIZHAIQUANA"],["980003","TPYLGYGDCYZ","太平洋六个月滚动持有债","债券型-长债","TAIPINGYANGLIUGEYUEGUNDONGCHIYOUZHAI"]]


如上所示: "中海可转债债
券A", 它们不在一起,影响形成数据帧,要怎么才能去掉空格或换行符什么的,使其在一起("中海可转债债券A")呢?

谢谢帮忙!
最佳答案
2023-3-28 00:11:09
示例代码:
import re

s = '''r = [["000001","HXCZHH","华夏成长混合","混合型-灵活","HUAXIACHENGZHANGHUNHE"],["000002","HXCZHH","华夏成长混合(后端)","混合型-灵活","HUAXIACHENGZHANGHUNHE"],["000003","ZHKZZZQA","中海可转债债
券A","债券型-可转债","ZHONGHAIKEZHUANZHAIZHAIQUANA"],["980003","TPYLGYGDCYZ","太平洋六个月滚动持有债","债券型-长债","TAIPINGYANGLIUGEYUEGUNDONGCHIYOUZHAI"]]
'''
result = re.sub(r'\s', '', s)
print(result)

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-3-28 00:11:09 | 显示全部楼层    本楼为最佳答案   
示例代码:
import re

s = '''r = [["000001","HXCZHH","华夏成长混合","混合型-灵活","HUAXIACHENGZHANGHUNHE"],["000002","HXCZHH","华夏成长混合(后端)","混合型-灵活","HUAXIACHENGZHANGHUNHE"],["000003","ZHKZZZQA","中海可转债债
券A","债券型-可转债","ZHONGHAIKEZHUANZHAIZHAIQUANA"],["980003","TPYLGYGDCYZ","太平洋六个月滚动持有债","债券型-长债","TAIPINGYANGLIUGEYUEGUNDONGCHIYOUZHAI"]]
'''
result = re.sub(r'\s', '', s)
print(result)

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-14 04:21

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表