Jupyter笔记本电脑加载\u ext signatu

2024-05-12 10:51:59 发布

您现在位置:Python中文网/ 问答频道 /正文

不久前,我发现了下面的website,我从中复制了源代码并将其粘贴到我自己的jupyter notebook。在

%load_ext signature
%matplotlib inline

import requests
import helpers

import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt

from lxml import html
from datetime import datetime

# Set style and meta info.
mpl.style.use('ramiro')
url = 'https://en.wikipedia.org/wiki/Wikipedia:Database_reports/Pages_with_the_most_revisions'
end_date = '27 March 2015'
chartinfo = 'Author: Ramiro Gómez - ramiro.org • Data: ' + url.replace('https://', '')
infosize = 12

# Extract first wikitable from page
xpath = '//*[contains(@class, "wikitable")]'
tree = html.fromstring(requests.get(url).text)
table = tree.xpath(xpath)[0]
raw_html = html.tostring(table)

# Create dataframe from html table
df = pd.read_html(raw_html, header=0, index_col='Page')[0]
df.index = df.index.map(lambda x: x.replace('_', ' '))
df.head(10)

现在我重新发现了这个笔记本并想运行它。但是,它不起作用:

^{pr2}$

我不知道为什么这个模块不见了,也不知道它到底做了什么。在

如何修复此问题并使代码运行?在

附加信息:

我有一个虚拟环境中的jupyter笔记本,它有以下软件包:

# packages in environment at /home/xiaolong/development/anaconda3/envs/jupyter:
#
abstract-rendering        0.5.1               np110py35_0    defaults
alabaster                 0.7.7                    py35_0    defaults
anaconda                  2.5.0               np110py35_0    defaults
anaconda-client           1.2.2                    py35_0    defaults
argcomplete               1.0.0                    py35_1    defaults
astropy                   1.1.1               np110py35_0    defaults
atlas                     0.27.0                    <pip>
babel                     2.2.0                    py35_0    defaults
beautifulsoup4            4.4.1                    py35_0    defaults
bitarray                  0.8.1                    py35_0    defaults
blaze                     0.9.0                     <pip>
blaze-core                0.9.0                    py35_0    defaults
bokeh                     0.11.0                   py35_0    defaults
boto                      2.39.0                   py35_0    defaults
bottleneck                1.0.0               np110py35_0    defaults
brewer2mpl                1.4.1                     <pip>
calysto-prolog            0.8.3                     <pip>
cffi                      1.2.1                    py35_0    defaults
clyent                    1.2.0                    py35_0    defaults
colorama                  0.3.6                    py35_0    defaults
configobj                 5.0.6                    py35_0    defaults
cryptography              1.0.2                    py35_0    defaults
curl                      7.45.0                        0    defaults
cycler                    0.9.0                    py35_0    defaults
cython                    0.23.4                   py35_0    defaults
cytoolz                   0.7.5                    py35_0    defaults
datashape                 0.5.0                    py35_0    defaults
decorator                 4.0.6                    py35_0    defaults
docutils                  0.12                     py35_0    defaults
dynd                      f641248                   <pip>
dynd-python               0.7.1                    py35_0    defaults
emcee                     2.1.0                     <pip>
et-xmlfile                1.0.1                     <pip>
et_xmlfile                1.0.1                    py35_0    defaults
fastcache                 1.0.2                    py35_0    defaults
flask                     0.10.1                   py35_1    defaults
fontconfig                2.11.1                        5    defaults
freetype                  2.5.5                         0    defaults
futures                   3.0.3                    py35_0    defaults
ggplot                    0.6.8                     <pip>
gmpy2                     2.0.7                     <pip>
greenlet                  0.4.9                    py35_0    defaults
h5py                      2.5.0               np110py35_4    defaults
hdf5                      1.8.15.1                      2    defaults
idna                      2.0                      py35_0    defaults
ipykernel                 4.2.2                    py35_0    defaults
ipython                   4.1.1                    py35_0    defaults
ipython-genutils          0.1.0                     <pip>
ipython-notebook          4.0.4                    py35_0    defaults
ipython-qtconsole         4.0.1                    py35_0    defaults
ipython_genutils          0.1.0                    py35_0    defaults
ipywidgets                4.1.1                    py35_0    defaults
itsdangerous              0.24                     py35_0    defaults
jbig                      2.1                           0    defaults
jdcal                     1.2                      py35_0    defaults
jedi                      0.9.0                    py35_0    defaults
jinja2                    2.8                      py35_0    defaults
jpeg                      8d                            0    <unknown>
jsonschema                2.4.0                    py35_0    defaults
jupyter                   1.0.0                    py35_1    defaults
jupyter-client            4.1.1                     <pip>
jupyter-console           4.1.0                     <pip>
jupyter-core              4.0.6                     <pip>
jupyter-kernel-test       0.1                       <pip>
jupyter_client            4.1.1                    py35_0    defaults
jupyter_console           4.1.0                    py35_0    defaults
jupyter_core              4.0.6                    py35_0    defaults
libdynd                   0.7.1                         0    defaults
libffi                    3.0.13                        0    <unknown>
libgfortran               1.0                           0    defaults
libpng                    1.6.17                        0    <unknown>
libsodium                 1.0.3                         0    defaults
libtiff                   4.0.6                         1    defaults
libxml2                   2.9.2                         0    <unknown>
libxslt                   1.1.28                        0    <unknown>
llvmlite                  0.8.0                    py35_0    defaults
lmfit                     0.8.2                     <pip>
lxml                      3.5.0                    py35_0    defaults
markupsafe                0.23                     py35_0    defaults
matplotlib                1.5.1               np110py35_0    defaults
metakernel                0.11.5                    <pip>
metakernel-bash           0.11.3                    <pip>
mistune                   0.7.1                    py35_0    defaults
mkl                       11.3.1                        0    defaults
mkl-service               1.1.2                    py35_0    defaults
multipledispatch          0.4.8                    py35_0    defaults
nbconvert                 4.1.0                    py35_0    defaults
nbformat                  4.0.1                    py35_0    defaults
networkx                  1.11                     py35_0    defaults
nltk                      3.1                      py35_0    defaults
nose                      1.3.7                    py35_0    defaults
notebook                  4.1.0                    py35_0    defaults
numba                     0.23.1              np110py35_0    defaults
numexpr                   2.4.6               np110py35_1    defaults
numpy                     1.10.4                   py35_0    defaults
octave-kernel             0.13.2                    <pip>
odo                       0.4.0                    py35_0    defaults
openblas                  0.2.14                        3    defaults
openpyxl                  2.3.2                    py35_0    defaults
openssl                   1.0.2f                        0    defaults
pandas                    0.17.1              np110py35_0    defaults
patchelf                  0.8                           0    defaults
path.py                   8.1.2                    py35_1    defaults
patsy                     0.4.0               np110py35_0    defaults
pep8                      1.7.0                    py35_0    defaults
pexpect                   3.3                      py35_0    defaults
pickleshare               0.5                      py35_0    defaults
pillow                    3.1.0                    py35_0    defaults
pip                       8.0.2                    py35_0    defaults
ply                       3.8                      py35_0    defaults
psutil                    3.4.2                    py35_0    defaults
ptyprocess                0.5                      py35_0    defaults
py                        1.4.31                   py35_0    defaults
pyaml                     15.8.2                    <pip>
pyasn1                    0.1.9                    py35_0    defaults
pycosat                   0.6.1                    py35_0    defaults
pycparser                 2.14                     py35_0    defaults
pycrypto                  2.6.1                    py35_0    defaults
pycurl                    7.19.5.3                 py35_0    defaults
pyflakes                  1.0.0                    py35_0    defaults
pygments                  2.1                      py35_0    defaults
pymatbridge               0.5.2                     <pip>
pyopenssl                 0.15.1                   py35_1    defaults
pyparsing                 2.0.3                    py35_0    defaults
pyqt                      4.11.4                   py35_1    defaults
pytables                  3.2.2               np110py35_0    defaults
pytest                    2.8.5                    py35_0    defaults
python                    3.5.1                         0    defaults
python-contrib-nbextensions alpha                     <pip>
python-dateutil           2.4.2                    py35_0    defaults
pytz                      2015.7                   py35_0    defaults
pyyaml                    3.11                     py35_1    defaults
pyzmq                     15.2.0                   py35_0    defaults
qt                        4.8.7                         1    defaults
qtconsole                 4.1.1                    py35_0    defaults
readline                  6.2                           2    <unknown>
redis                     2.6.9                         0    <unknown>
redis-py                  2.10.3                   py35_0    defaults
requests                  2.9.1                    py35_0    defaults
rope                      0.9.4                    py35_1    defaults
rope-py3k                 0.9.4.post1               <pip>
satlas                    0.1.0b17                  <pip>
scikit-image              0.11.3              np110py35_0    defaults
scikit-learn              0.17                np110py35_2    defaults
scipy                     0.17.0              np110py35_1    defaults
setuptools                19.6.2                   py35_0    defaults
simplegeneric             0.8.1                    py35_0    defaults
sip                       4.16.9                   py35_0    defaults
six                       1.10.0                   py35_0    defaults
snowballstemmer           1.2.1                    py35_0    defaults
sockjs-tornado            1.0.1                    py35_0    defaults
sphinx                    1.3.5                    py35_0    defaults
sphinx-rtd-theme          0.1.9                     <pip>
sphinx_rtd_theme          0.1.9                    py35_0    defaults
spyder                    2.3.8                    py35_0    defaults
spyder-app                2.3.8                    py35_0    defaults
sqlalchemy                1.0.11                   py35_0    defaults
sqlite                    3.9.2                         0    defaults
statsmodels               0.6.1               np110py35_0    defaults
sympy                     0.7.6.1                  py35_0    defaults
tables                    3.2.2                     <pip>
terminado                 0.5                      py35_1    defaults
threadpool                1.3.2                     <pip>
tk                        8.5.18                        0    <unknown>
toolz                     0.7.4                    py35_0    defaults
tornado                   4.3                      py35_0    defaults
tqdm                      3.8.0                     <pip>
traitlets                 4.1.0                    py35_0    defaults
unicodecsv                0.14.1                   py35_0    defaults
util-linux                2.21                          0    <unknown>
werkzeug                  0.11.3                   py35_0    defaults
wheel                     0.29.0                   py35_0    defaults
xlrd                      0.9.4                    py35_0    defaults
xlsxwriter                0.8.4                    py35_0    defaults
xlwt                      1.0.0                    py35_0    defaults
xz                        5.0.5                         1    defaults
yaml                      0.1.6                         0    <unknown>
zeromq                    4.1.3                         0    defaults
zlib                      1.2.8                         0    <unknown>

Tags: pipfromimportdfmatplotlibhtmlasipython
2条回答

我也面对这个问题,做了一点探索,解决了。在

请阅读%load_extmagic。显然signature是一个扩展,要使用它,您需要先安装它。在

现在的问题是你需要找到签名的密码。在

我花了很长时间才找到密码。这篇教程是由拉米罗戈梅兹写的,我在github and the script上找到了他的网页。在

要安装,可以在ipythonshell中使用%install_ext魔法。在

安装:

conda install -c conda-forge python-magic 

创建文件“签名.py“->;链接Ramiro Gómez's script并将其添加到文件夹中。完成!在

相关问题 更多 >