python-报错集合

1. 使用pydub时报错

RuntimeWarning: Couldn't find ffplay or avplay - defaulting to ffplay, but may not work
  warn("Couldn't find ffplay or avplay - defaulting to ffplay, but may not work", RuntimeWarning)
[Errno 13] Permission denied: 'C:\\Users\\MyPC\\AppData\\Local\\Temp\\tmpkb_z2s33.wav'

解决
windows上需要安装ffmpeg,要先下载https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-2023-05-04-git-4006c71d19-full_build.7z解压,将目录中的bin文件夹路径加入系统环境变量

2. 使用sklearn的joblib库报错

from sklearn.externals import joblib
cannot import name 'joblib' from 'sklearn.externals'

解决
安装conda install joblib
import joblib

3. 使用pandas读取csv时报错ParserError:Error tokenizing data.C error:Expected 2 fields in line 407,saw 3.

ParserError:Error tokenizing data.C error:Expected 2 fields in line 407,saw 3.

解决
加入参数error_bad_lines=False
pandas.read_csv(filePath,error_bad_lines=False)

4. 访问dataframe报错’DataFrame’ object is not callable

ctype("Date")
'DataFrame' object is not callable

解决
应该使用ctype[“Date”]

5. 对模型打分报错Target is multiclass but average=‘binary’. Please choose another average setting, one of [None, ‘micro’, ‘macro’, ‘weighted’].

Target is multiclass but average='binary'. Please choose another average setting, one of [None, 'micro', 'macro', 'weighted'].

解决
需要增加average参数

f1_score(y_test, y_predict, average='micro')
precision_score(y_test, y_predict, average='weighted')

6. read_csv报错

6.1

MemoryError: Unable to allocate 128. KiB for an array with shape (16384,) and data type float64
Error tokenizing data. C error: out of memory

解决
关掉不用的notebook,一般是内存不够了

6.2

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xcc in position 0: invalid continuation byte

解决
encoding中更换各种编码:gbk2132 gbk gb18030

6.3

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

解决
有可能是的文件路径没有,如果是windows,需要加双斜杠

df=pd.read_csv("C:\\Users\\xxxx\\Downloads\30.csv",encoding="gbk")```

7. resample报错 Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of ‘Index’

df.index=pd.to_datetime(df.index)
或者
df["date"] = pd.to_datetime(df["时间列"])
df=df.set_index(df["date"])

8. 执行dataframe的append方法报错AttributeError: ‘DataFrame’ object has no attribute ‘append’

AttributeError: 'DataFrame' object has no attribute 'append'

解决
使用pd的concat

df=pd.concat([df,c],ignore_index=True)

9. 实例化SelectKBest时卡方检验报错 name ‘chi2’ is not defined

 name 'chi2' is not defined

解决
chi2也需要导入包:from sklearn.feature_selection import SelectKBest,chi2

10. 模型fit时报错 Unknown label type: ‘continuous’

解决方法:y=y.astype(str)或者y=y.astype(int)

11.过采样设定ration报错 init() got an unexpected keyword argument ‘ratio’

解决方法:sampling_strategy代替ration

12. 使用DataLoader导入数据时报错ValueError: num_samples should be a positive integer value, but got num_samples=0

解决方法:shuffle=False

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值