python的问题日常

一 、TypeError: sequence ietm 0:expected str tuple found

string.join connects elements inside list of strings, not ints.

Use this generator expression instead :

values = ','.join(str(v) for v in value_list)

二 、多行左移

在使用pycharm时,经常会需要多行代码同时缩进、左移,pycharm提供了快捷方式

1、pycharm使多行代码同时缩进

   鼠标选中多行代码后,按下Tab键,一次缩进四个字符

2、pycharm使多行代码同时左移

  鼠标选中多行代码后,同时按住shift+Tab键,一次左移四个字符

三、'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

参考:

https://www.cnblogs.com/Alier/p/6794719.html

代码:

stopwords = pd.read_csv("stopwords.txt",index_col=False,quoting=3,sep=" ",names=['stopword'],encoding='UTF-8')

报错:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa1 in position 0

Python 编码中编码解码的问题,我这个错误就是‘utf-8’不能解码位置0的那个字节(0xa1),也就是这个字节超出了utf-8的表示范围了

解决办法:

stopwords = pd.read_csv("stopwords.txt",index_col=False,quoting=3,sep=" ",names=['stopword'],encoding='gb18030')

也就是在读取数据的时候,显式添加编码方式encoding='gb18030',别的编码也可以试试哟
 

猜你喜欢

转载自blog.csdn.net/qq_34333481/article/details/84333874