0
点赞
收藏
分享

微信扫一扫

Python之Pyforest:Pyforest的简介、安装、使用方法之详细攻略


Python之Pyforest:Pyforest的简介、安装、使用方法之详细攻略


目录

​​pyforest简介​​

​​pyforest安装​​

​​pyforest使用方法​​


pyforest简介

        pyforest,感受自动导入的幸福,来自[bamboolib]的制作者(​​​https://bamboolib.com​​​)。如果一遍又一遍地写同样的导入是你的能力所不及的,那么就让pyforest替你做这件事吧。使用pyforest,您可以使用所有喜欢的Python库,而无需之前导入它们。如果您使用的包尚未导入,则pyforest将为您导入该包并将代码添加到第一个Jupyter单元中。如果您不使用库,它将不会被导入。

        如果你是一名使用Python的数据科学家。每天你都要开始多本新的木星笔记本,因为你想要探索一些数据或验证一个假设。在您的工作中,您将使用许多不同的库,如“pandas”、“matplotlib”、“seaborn”、“numpy”或“sklearn”。但是,在开始实际工作之前,您总是需要导入您的库。这还有其他几个问题。不可否认,它们很小,但随着时间的推移,它们会累积起来。


  • -很无聊,因为进口的都是一样的。这超出了你的能力范围。
  • -缺少导入扰乱你的工作的自然流程。
  • -有时,您甚至可能需要查找确切的导入声明。例如,import matplotlib。pyplot作为sklearn的plt '或'。整体进口GradientBoostingRegressor”

如果你能专注于使用这些图书馆呢?pyforest提供了以下剩余的解决方案:


  • -你可以像往常一样使用你所有的库。如果还没有导入库,则pyforest将导入库并将导入语句添加到第一个Jupyter单元中。
  • -如果一个库不被使用,它将不会被导入。
  • -你的笔记本保持可复制和共享没有你浪费一个想法的imports。


1、使用pyforest

       在您[安装](#installation) pyforest和它的Jupyter扩展之后,您就可以像平常一样继续使用您最喜欢的Python数据科学命令——而不需要编写imports__。

For example, if you want to read a CSV with pandas:

```python
df = pd.read_csv("titanic.csv")
```

pyforest will automatically import pandas for you and add the import statement to the first cell:
```python
import pandas as pd
```



pyforest安装

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyforest

Python之Pyforest:Pyforest的简介、安装、使用方法之详细攻略_python



pyforest使用方法

# -*- coding: utf-8 -*-
from ._imports import *
from .utils import (
get_user_symbols,
install_extensions,
install_nbextension,
install_labextension,
)

user_symbols = get_user_symbols()
pyforest_imports = globals().copy().keys()

for import_symbol in pyforest_imports:
# don't overwrite symbols of the user
if import_symbol not in user_symbols.keys():
user_symbols[import_symbol] = eval(import_symbol)


# set __version__ attribute
from pkg_resources import get_distribution, DistributionNotFound

try:
__version__ = get_distribution(__name__).version
except DistributionNotFound:
__version__ = "unknown"
finally:
del get_distribution, DistributionNotFound


def _jupyter_nbextension_paths():
return [
{
"section": "notebook",
"src": "static",
"dest": "pyforest",
"require": "pyforest/nbextension",
}
]


def _jupyter_labextension_paths():
return [{"name": "pyforest", "src": "static"}]


举报

相关推荐

0 条评论