小编Har*_*rry的帖子

BeautifulSoup4 无法在 Windows7 上的 python3.5 中安装

我已经从https://www.crummy.com/software/BeautifulSoup/bs4/download/4.5/下载了 beautifulsoup4-4.5.3.tar.gz并将其解压缩到我的 python 工作目录(这不是我的 python 安装目录) .

然而,当我跑

from bs4 import BeautifulSoup
Run Code Online (Sandbox Code Playgroud)

在我的 IDLE 中,错误消息弹出:

>>> from bs4 import BeautifulSoup
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
from bs4 import BeautifulSoup
File "D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3\bs4\__init__.py", 
line 53
'You are trying to run the Python 2 version of Beautiful Soup under Python 
3. This will not work.'<>'You need to convert the code, either by installing 
it (`python setup.py install`) or by running 2to3 (`2to3 -w …
Run Code Online (Sandbox Code Playgroud)

windows installation beautifulsoup python-2to3 python-3.x

5
推荐指数
1
解决办法
1万
查看次数

groupby和均值后的“没有要聚合的数字类型”

我正在处理时间序列,并尝试编写函数以计算数据的每月平均值。以下是一些准备功能:

import datetime
import numpy as numpy
def date_range_0(start,end):

    dates = [start + datetime.timedelta(days=i) 
            for i in range((end-start).days+1)]
    return numpy.array(dates)
def date_range_1(start,days):
    #days should be an interger

    return date_range_0(start,start+datetime.timedelta(days-1))

x=date_range_1(datetime.datetime(2015, 5, 17),4)
Run Code Online (Sandbox Code Playgroud)

x,输出是一个简单的时间列表:

array([datetime.datetime(2015, 5, 17, 0, 0),
   datetime.datetime(2015, 5, 18, 0, 0),
   datetime.datetime(2015, 5, 19, 0, 0),
   datetime.datetime(2015, 5, 20, 0, 0)], dtype=object)
Run Code Online (Sandbox Code Playgroud)

然后,我从http://blog.csdn.net/youngbit007/article/details/54288603学习了groupby函数, 我已经在上面的网站中尝试了一个示例,并且工作正常:

df = pandas.DataFrame({'key1':date_range_1(datetime.datetime(2015, 1, 17),5),
              'key2': [2015001,2015001,2015001,2015001,2015001],
              'data1': 1+0.1*numpy.arange(1,6)
        })
df
Run Code Online (Sandbox Code Playgroud)

   data1    key1    key2
0   1.1 2015-01-17  2015001
1   1.2 2015-01-18 …
Run Code Online (Sandbox Code Playgroud)

python pandas

3
推荐指数
2
解决办法
4451
查看次数