社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

代码在spyder(Python3,7)中有效,但在Jupyter笔记本中无效

YM1 • 5 年前 • 1762 次点击  

以下代码适用于spyder

import re

price_num = []
for row in df['price']:
    price_no_nonnum = re.sub('[^0-9]','', row) # this code line works in spyder
    price_num.append(int(price_no_nonnum))

import re

price_num = []
for row in df['price']:
    price_no_nonnum = re.sub('[^0-9]','', row) # this code line gives an error in  jupyter
    price_num.append(int(price_no_nonnum))

Jupyter中出现以下错误

TypeErrorTraceback (most recent call last)
<ipython-input-13-b3f4fcbe9d89> in <module>()
      3 price_num = []
      4 for row in autos['price']:
----> 5    price_no_nonnum = re.sub("[^0-9]","", row)
      6    price_num.append(int(price_no_nonnum))
      7 

/dataquest/system/env/python3/lib/python3.4/re.py in sub(pattern, repl, string, count, flags)
    177     a callable, it's passed the match object and must return
    178     a replacement string to be used."""
--> 179     return _compile(pattern, flags).sub(repl, string, count)
    180 
    181 def subn(pattern, repl, string, count=0, flags=0):

TypeError: expected string or buffer
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/53654
 
1762 次点击  
文章 [ 1 ]  |  最新文章 5 年前