Debug
文章平均质量分 50
python编程中常见的bug说明
千行百行
这个作者很懒,什么都没留下…
展开
-
sklearn中GradientBoostingClassifier bug:ValueError: Input contains NaN, infinity or a value too large
sklearn的GradientBoostingClassifier真的支持缺失值处理吗???原创 2022-04-22 17:05:44 · 2486 阅读 · 0 评论 -
TypeError: ‘<=‘ not supported between instances of ‘list‘ and ‘int‘
debug原创 2022-04-17 22:06:31 · 8381 阅读 · 0 评论 -
ValueError: cannot convert float NaN to integer
文章目录问题复现报错解决方案问题复现import numpy as npa = np.arange(10)a[1] = np.nan报错ValueError: cannot convert float NaN to integer解决方案a.astype(float)a[1] = np.nan先把a转化成float类型的即可。原创 2022-02-26 12:47:24 · 12157 阅读 · 1 评论 -
git pull 报错 error: cannot pull with rebase: You have unstaged changes
git pull报错error: cannot pull with rebase: You have unstaged changes.error: please commit or stash them.解决办法把没有提交的修改全都提交了,然后重新执行git pull原创 2022-02-25 22:18:26 · 15401 阅读 · 2 评论 -
TypeError: ‘coo_matrix‘ object is not subscriptable
错误复现from scipy.sparse import coo_matriximport numpy as nprow = np.array([0, 3, 1, 0])col = np.array([0, 3, 1, 2])data = np.array([4, 5, 7, 9])coo = coo_matrix((data, (row, col)), shape=(4, 4))element = coo[0, 0]报错TypeError: 'coo_matrix' object原创 2022-01-19 17:10:24 · 3196 阅读 · 0 评论 -
使用matplotlib绘图添加标题title时出现TypeError: ‘Text‘ object is not callable,这么改就对了
文章目录错误复现报错解决办法plt.title和ax.set_titlesee also错误复现import matplotlib.pyplot as pltimport numpy as npimport mathx = np.arange(1000)y = np.sin(2*math.pi*x/1000)fig, ax = plt.subplots()ax.plot(x, y)ax.title("sine") # 报错:TypeError: 'Text' object is no原创 2021-10-17 22:09:17 · 8140 阅读 · 0 评论 -
TypeError: unsupported operand type(s) for /: ‘str‘ and ‘int‘
文章目录错误复现报错解决办法错误复现# python代码print('1除以2等于%f' %1/2)报错TypeError: unsupported operand type(s) for /: 'str' and 'int'解决办法加上括号即可>>> print('1除以2等于%f' %(1/2))1除以2等于0.500000...原创 2021-07-08 20:14:13 · 5926 阅读 · 1 评论 -
ValueError: non convertible value 2021-02-09 20:22 with the unit ‘s‘
文章目录错误复现报错及原因解决方案错误复现import pandas as pdpd.to_datetime('2021-02-09 20:22', unit='s')报错及原因ValueError: could not convert string to float: ‘2021-02-09 20:22’ValueError: non convertible value 2021-02-09 20:22 with the unit ‘s’仔细看官方文档发现,使用unit这个参数的时候,第一原创 2021-05-10 23:06:28 · 2481 阅读 · 1 评论 -
DeprecationWarning: parsing timezone aware datetimes is deprecated
错误复现import numpy as pya = np.datetime64('1970-01-01T08:00:00') - np.datetime64('1970-01-01T08:00:00Z')报警及原因DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future'1970-01-01T08:00:00Z’中的“Z”表示时区,仔细看两个原创 2021-05-10 22:36:56 · 802 阅读 · 0 评论 -
scipy.signal.medfilt出现UserWarning: kernel_size exceeds volume extent: the volume will be zero-padded
文章目录错误复现错误原因see also错误复现import scipy.signal as signalimport numpy as npx = np.arange(0, 100, 10)np.random.shuffle(x)x_filtered = signal.medfilt(x, 9)# 以下是错误示例,就是下面的代码触发了UserWarningx_1 = x.reshape(-1, 1)x_filtered_1 = signal.medfilt(x_1, 9)从结果中(原创 2021-04-11 21:35:15 · 960 阅读 · 1 评论 -
python TypeError: list indices must be integers or slices, not list
文章目录错误复现报错及原因解决办法错误复现a = [1,2,3]b = a[[0,2]]报错及原因TypeError: list indices must be integers or slices, not listlist数据结构不支持从list中取两个下标/索引不连续的元素解决办法a = [1,2,3]import numpy as npb = [a[0], a[2]]当然这种解决办法略显笨拙,而且如果想提取的元素很多的话就很麻烦,更好的解决办法详见:python从list中原创 2021-04-07 20:58:15 · 24226 阅读 · 0 评论 -
python TypeError: list indices must be integers or slices, not tuple
文章目录错误复现报错及原因解决办法错误复现a = [1,2,3]b = a[(0,2)]报错及原因TypeError: list indices must be integers or slices, not tuplelist数据结构不支持从list中取两个下标/索引不连续的元素解决办法a = [1,2,3]import numpy as npb = [a[0], a[2]]当然这种解决办法略显笨拙,而且如果想提取的元素很多的话就很麻烦,更好的解决办法详见:python从list原创 2021-04-07 20:58:04 · 708 阅读 · 0 评论 -
python TypeError: ‘numpy.ndarray‘ object is not callable
文章目录错误复现报错解决办法错误复现import numpy as npa = np.arange(5)b = a(0)报错TypeError: ‘list’ object is not callable解决办法把第三行的圆括号改成方括号即可,取第1个元素是用方括号!import numpy as npa = np.arange(5)b = a[0]...原创 2021-04-07 20:17:42 · 1462 阅读 · 0 评论 -
python TypeError: ‘list‘ object is not callable
文章目录错误复现报错解决办法错误复现a = [1,2,3]b = a(0)报错TypeError: ‘list’ object is not callable解决办法把第二行的圆括号改成方括号即可,取第一个元素是用方括号!a = [1,2,3]b = a[0]原创 2021-04-07 20:02:44 · 375 阅读 · 0 评论 -
AttributeError: ‘AxesSubplot‘ object has no attribute ‘ylabel‘,matplotlib报错
解决bug原创 2021-03-12 11:51:49 · 9756 阅读 · 3 评论 -
python使用json.loads时出现raise JSONDecodeError(“Expecting value“, s, err.value) from None
解决bug,对症下药原创 2020-07-22 20:38:55 · 22979 阅读 · 0 评论 -
TypeError: ‘<‘ not supported between instances of ‘NoneType‘ and ‘int‘
debug原创 2021-01-01 21:10:47 · 22880 阅读 · 2 评论 -
从AttributeError: module ‘pandas‘ has no attribute ‘dataframe‘说开去
提供了排除bug的解决方案,额外提出了防止出现此类bug的措施原创 2021-02-12 17:56:59 · 5429 阅读 · 1 评论