栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

numpy.concatenate() 报错 Keyerror: 0

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

numpy.concatenate() 报错 Keyerror: 0

numpy.concatenate()

官方文档链接

函数说明:

Join a sequence of arrays along an existing axis.
沿现有轴连接阵列序列。


程序报错:

KeyError Traceback (most recent call last)
F:Anacondaaalibsite-packagespandascoreindexesbase.py in get_loc(self, key, method, tolerance)
3079 try:
-> 3080 return self._engine.get_loc(casted_key)
3081 except KeyError as err:

pandas_libsindex.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas_libsindex.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas_libshashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

pandas_libshashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: 0

The above exception was the direct cause of the following exception:

KeyError Traceback (most recent call last)
in
----> 1 np.unique(np.concatenate(movie_type[‘类型’].map(lambda x: x.split(’/’))))

in concatenate(*args, **kwargs)

F:Anacondaaalibsite-packagespandascoreseries.py in getitem(self, key)
851
852 elif key_is_scalar:
–> 853 return self._get_value(key)
854
855 if is_hashable(key):

F:Anacondaaalibsite-packagespandascoreseries.py in _get_value(self, label, takeable)
959
960 # Similar to Index.get_value, but we do not fall back to positional
–> 961 loc = self.index.get_loc(label)
962 return self.index._get_values_for_loc(self, loc, label)
963

F:Anacondaaalibsite-packagespandascoreindexesbase.py in get_loc(self, key, method, tolerance)
3080 return self._engine.get_loc(casted_key)
3081 except KeyError as err:
-> 3082 raise KeyError(key) from err
3083
3084 if tolerance is not None:

KeyError: 0


原因及建议

keyerror 就是没这条数据的意思,因为 np.concatenate 本身是以原有的索引进行连接的,此时没有成功是因为在数据清洗的过程中原索引不再连续。
重置连续的索引、或使用其他能使列表连接的方法即可实现此效果。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/296158.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号