在jupyter notebook运行画图遇到InvalidIndexError: (slice(None, None, None), None)解决
错误代码
x_data = pd.read_csv('E:/bear3/3_3v_tezheng/liutezheng/x.txt',header=None)
y_data = pd.read_csv('E:/bear3/3_3v_tezheng/liutezheng/nengliangshang_guiyihua.txt',header=None)plt.plot(x_data[730:832],y_data[730:832])
plt.show()
错误:
TypeError Traceback (most recent call last) File E:\anaconda\lib\site-packages\pandas\core\indexes\base.py:3621, in Index.get_loc(self, key, method, tolerance)3620 try: -> 3621 return self._engine.get_loc(casted_key)3622 except KeyError as err:File E:\anaconda\lib\site-packages\pandas\_libs\index.pyx:136, in pandas._libs.index.IndexEngine.get_loc()File E:\anaconda\lib\site-packages\pandas\_libs\index.pyx:142, in pandas._libs.index.IndexEngine.get_loc()TypeError: '(slice(None, None, None), None)' is an invalid keyDuring handling of the above exception, another exception occurred:InvalidIndexError Traceback (most recent call last) Input In [62], in <cell line: 3>()1 # x_data = np.array(x_data,type(float))2 # y_data = np.array(y_data,type(float)) ----> 3 plt.plot(x_data[730:832],y_data[730:832])4 # plt.plot(x_data[730:832],predict)5 plt.show()File E:\anaconda\lib\site-packages\matplotlib\pyplot.py:2757, in plot(scalex, scaley, data, *args, **kwargs)2755 @_copy_docstring_and_deprecators(Axes.plot)2756 def plot(*args, scalex=True, scaley=True, data=None, **kwargs): -> 2757 return gca().plot(2758 *args, scalex=scalex, scaley=scaley,2759 **({"data": data} if data is not None else {}), **kwargs)File E:\anaconda\lib\site-packages\matplotlib\axes\_axes.py:1632, in Axes.plot(self, scalex, scaley, data, *args, **kwargs)1390 """1391 Plot y versus x as lines and/or markers.1392 (...)1629 (``'green'``) or hex strings (``'#008000'``).1630 """1631 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D) -> 1632 lines = [*self._get_lines(*args, data=data, **kwargs)]1633 for line in lines:1634 self.add_line(line)File E:\anaconda\lib\site-packages\matplotlib\axes\_base.py:312, in _process_plot_var_args.__call__(self, data, *args, **kwargs)310 this += args[0],311 args = args[1:] --> 312 yield from self._plot_args(this, kwargs)File E:\anaconda\lib\site-packages\matplotlib\axes\_base.py:488, in _process_plot_var_args._plot_args(self, tup, kwargs, return_kwargs)486 if len(xy) == 2:487 x = _check_1d(xy[0]) --> 488 y = _check_1d(xy[1])489 else:490 x, y = index_of(xy[-1])File E:\anaconda\lib\site-packages\matplotlib\cbook\__init__.py:1327, in _check_1d(x)1321 with warnings.catch_warnings(record=True) as w:1322 warnings.filterwarnings(1323 "always",1324 category=Warning,1325 message='Support for multi-dimensional indexing') -> 1327 ndim = x[:, None].ndim1328 # we have definitely hit a pandas index or series object1329 # cast to a numpy array.1330 if len(w) > 0:File E:\anaconda\lib\site-packages\pandas\core\frame.py:3505, in DataFrame.__getitem__(self, key)3503 if self.columns.nlevels > 1:3504 return self._getitem_multilevel(key) -> 3505 indexer = self.columns.get_loc(key)3506 if is_integer(indexer):3507 indexer = [indexer]File E:\anaconda\lib\site-packages\pandas\core\indexes\base.py:3628, in Index.get_loc(self, key, method, tolerance)3623 raise KeyError(key) from err3624 except TypeError:3625 # If we have a listlike key, _check_indexing_error will raise3626 # InvalidIndexError. Otherwise we fall through and re-raise3627 # the TypeError. -> 3628 self._check_indexing_error(key)3629 raise3631 # GH#42269File E:\anaconda\lib\site-packages\pandas\core\indexes\base.py:5637, in Index._check_indexing_error(self, key)5633 def _check_indexing_error(self, key):5634 if not is_scalar(key):5635 # if key is not a scalar, directly raise an error (the code below5636 # would convert to numpy arrays and raise later any way) - GH29926 -> 5637 raise InvalidIndexError(key)InvalidIndexError: (slice(None, None, None), None)
其实明面上看,程序本身并没有错误,但就是错在数据文本格式上,解决方案如下。
x_data = np.array(x_data,type(float))
y_data = np.array(y_data,type(float))
plt.plot(x_data[730:832],y_data[730:832])plt.show()
这样图片就出来了啊,其实不知道什么原因,哪里错了就直接打印出来,就好解决了。
在jupyter notebook运行画图遇到InvalidIndexError: (slice(None, None, None), None)解决相关推荐
- Jupyter notebook 运行环境创建和切换 (Win10+Anaconda)
1. 激活Jupyter notebook运行需要的虚拟环境 activate pytorch-gpu pytorch-gpu 为环境名 2. 在当前环境下安装 Jupyter (pytorch-gp ...
- jupyter notebook运行报404 302解决思路
笔者之前运行juputer notebook并没有出错 ,最近运行突然出现以下问:题jupyter notebook运行命令行报404 302,web界面无法加载文件夹以及点击新建按钮,出现404. ...
- Jupyter notebook运行后打不开网页
前言: 最近正在上一门Python数据处理的课程,要用到Jupyter,于是就先安装了anaconda,当我正准备运行Jupyter时点了一下launch,没反应-于是又点了一遍,还是没反应-很迷,正 ...
- 【MacBook M1】 安装动手学深度学习d2l包+jupyter notebook运行
文章目录 一.下载d2l包 二.jupyter notebook运行 1.错误尝试 2.正确做法 一.下载d2l包 这是我主要参考的博客 这里假设已经安装好了miniforge3.python.pyt ...
- jupyter notebook运行出错:ModuleNotFoundError: No module named ‘keras‘ 解决办法
接上一篇 <win10+python3.6+tensorflow-cpu+keras+Pycharm环境下的tensorflow配置方法> 通过Anaconda Prompt 打开 查看当 ...
- jupyter notebook运行没反应_搭建Jupyter Notebook远程云服务器(Jupyter配置)
搭建Jupyter Notebook远程云服务器yuenshui.cn 前面讲了Jupyter Notebook的远程服务器搭建过程.但每次打开一个新的notebook,都要重复地倒入一些模块(pa ...
- Jupyter Nodebook添加代码提示(Vscode配置Jupyter Notebook运行.ipynb文件)
2021.04.14 更新,增加了对Vscode代码提示消失的描述 前言 由于Jupyter Notebook调试Python代码十分方便,受到了许多Coder的欢迎,但是它存在个十分不方便的地方-- ...
- python matplotlab在jupyter notebook中画图不显示怎么办?(%matplotlib inline)
在程序中代码最上方加上: 总结:%matplotlib inline 可以在Ipython编译器里直接使用,功能是可以内嵌绘图,并且可以省略掉plt.show()这一步. 引用文章1: 解决jupyt ...
- Windows下 jupyter notebook 运行multiprocessing 报错的问题与解决方法
文章目录 测试用的代码 错误 解决方法 测试用的代码 下面每一个对应一个jupyter notebook的单元格 import time from multiprocessing import Pro ...
最新文章
- 大学毕业想要转行学软件测试,怎样入门比较好?
- 吴恩达机器学习笔记 —— 3 线性回归回顾
- php上传图片完成后的截图,php实现粘贴截图并完成上传功能
- python http 返回json中文乱码
- 文档下载:《Oracle 20c和19c的新特性解密》
- 成为java架构师需要具备那些技能?
- WampServer服务器离线问题的解决方法
- 多模态中预训练的演变史
- 20个非常棒的Jquery实用工具
- RMAN-20201: datafile not found in the recovery catalog
- 管家婆服务器备份文件夹,[任我行]管家婆软件的使用方法,管家婆辉煌提示备份报错3202...
- HenCoder Plus L02—— 编码、加密、Hash
- 快速入门linux(收藏版)
- cdrx8如何批量导出jpg_cdr怎么保存jpg格式
- qt5 开发及实例(第4版)_张厚粲现代心理与教育统计学第4版配套章节题库
- 为什么总是封板又打开涨停_股票反复打开涨停是什么原因?
- /admin/login.php,app/admin/controller/Login.php · 静水流深/wotuoquan - Gitee.com
- Android 4.1新特性
- 公司文案编辑常用迅捷PDF转换成Word转换器
- 汇智网node学习笔记
热门文章
- CentOS7出现 Detected CPU family 6 model 165 stepping 3
- 数据流图的画法及其三大原则
- 关于webapp和WEB-INF
- 基于EV/EBITDA倍数估值法的Alpha对冲策略
- 基于EVEBITDA倍数估法Alpha对冲策略(源码)
- 样本估计量的有偏估计和无偏估计
- java pmd checkstyle_maven配置pom文件添加PMD检查,添加checkStyle检查,JDepend等检查功能...
- 企业网站宣传画册设计制作的重要性
- 移动平均算法的实现方法
- Asp.Net MVC实现优酷(youku)Web的上传