报错解决:could not convert string to float: ‘‘

可能存在空值list类型空值去除方法


while "" in tmp_list:# 判断是否有空值在列表中
    tmp_list.remove("")# 如果有就直接通过remove删除
print(tmp_list)

str类型空值去除方法
1、strip方法去掉字符串两边(开头和结尾)的空格

space_str = ’ Remove the space around the string ’

print(space_str.strip())

2、lstrip方法去掉字符串左边的空格

left_space_str = ’ Remove the space to the left of the string ’

print(left_space_str.lstrip())

3、rstrip方法去掉字符串右边的空格

right_space_str = ’ Remove the space to the right of the string ’

print(right_space_str.rstrip())

4、replace方法替换字符串的空格为空

all_space_str = ’ The space of the replacement string is empty ’

print(all_space_str.replace(’ ', ‘’)

注意:这里说一下replace方法的具体用法

str.replace(old_str, new_str, [max])

old_str:代表原来的字符串,new_str:代表替换之后的字符串,max:代表替换的次数

5、正则匹配替换空格

import re

all_str = " Regular matching without spaces "

print(re.sub(r"\s+", “”, all_str))

本文为学习笔记,仅是个人意见,仅供交流学习,请勿用于非法途径
转自https://blog.csdn.net/weixin_32340083/article/details/116183516

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值