前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >数据分析 常见异常及解决办法(一)

数据分析 常见异常及解决办法(一)

作者头像
cutercorley
发布2020-08-26 22:23:44
5K1
发布2020-08-26 22:23:44
举报

1.Jupyter读取数据警告ParserWarning: Falling back to the ‘python’ engine because the ‘c’ engine does not support regex separators

在使用Jupyter Notebook读取数据进行分析时,如下:

<ipython-input-5-9af9eaa72e92>:5: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'.
  users = pd.read_csv('users.dat',sep = '::',header = None,names = labels)

提示C引擎不支持正则表达式分割,需要使用Python引擎,此时只需要在读取数据文件时加入参数,engine='python'即可,如下:

users = pd.read_csv('users.dat',sep = '::',header = None,names = labels, engine='python')

此时再执行就不会再提示警告信息了。

2.使用matplotlib画图警告 RuntimeWarning: Glyph 30005 missing from current font

在使用matplotlib库进行画图时,如果标题等文字中出现中文,就可能出现警告:

E:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:214: RuntimeWarning: Glyph 30005 missing from current font.
  font.set_text(s, 0.0, flags=flags)
E:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:214: RuntimeWarning: Glyph 24433 missing from current font.
  font.set_text(s, 0.0, flags=flags)
E:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:214: RuntimeWarning: Glyph 25968 missing from current font.
  font.set_text(s, 0.0, flags=flags)
E:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:214: RuntimeWarning: Glyph 25454 missing from current font.
  font.set_text(s, 0.0, flags=flags)
E:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:214: RuntimeWarning: Glyph 25454 missing from current font.
  font.set_text(s, 0.0, flags=flags)

意思是plt画图找不到字体,需要进行配置。 有两种方式:

  • 临时设置 在调用画图函数前进行配置: plt.rcParams['font.sans-serif']=['Microsoft YaHei'] #显示中文标签 plt.rcParams['axes.unicode_minus']=False 即设置字体为微软雅黑,支持中文。 但是这只是临时设置,下一次再使用又得设置,显得很麻烦。
  • 永久配置 永久设置是编辑matplotlib的配置文件matplotlibrc,修改后以后无需再修改、一劳永逸。该文件一般位于%PythonPath%\Lib\site-packages\matplotlib\mpl-data(PythonPath即表示安装的Python路径),如果使用的是Anaconda,则是%AnacondaPath%\Lib\site-packages\matplotlib\mpl-data(AnacondaPath表示Anaconda的安装路径)。 在matplotlibrc文件中找到如下位置(定义font.family处):
font.family
font.family

修改如下: ## The font.size property is the default font size for text, given in pts. ## 10 pt is the standard value. ## ## Note that font.size controls default text sizes. To configure ## special text sizes tick labels, axes, labels, title, etc, see the rc ## settings for axes and ticks. Special text sizes can be defined ## relative to font.size, using the following values: xx-small, x-small, ## small, medium, large, x-large, xx-large, larger, or smaller font.family : monospace font.monospace : Microsoft YaHei, SimHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif #font.style : normal #font.variant : normal #font.weight : normal #font.stretch : normal #font.size : 10.0 主要是第10、11行,设置font.family : monospace取消#注释,添加一行font.monospace : Microsoft YaHei, SimHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serifMicrosoft YaHei为微软雅黑、SimHei为黑体、支持中文。 然后再重启Jupyter Notebook或者重新运行代码即可显示中文,如下:

中文字体正常显示
中文字体正常显示
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-08-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1.Jupyter读取数据警告ParserWarning: Falling back to the ‘python’ engine because the ‘c’ engine does not support regex separators
  • 2.使用matplotlib画图警告 RuntimeWarning: Glyph 30005 missing from current font
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档