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

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

yforest简介


       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

image.png





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"}]

 


相关文章
|
1天前
|
Ubuntu Python
Ubuntu 安装Python3.8
Ubuntu 安装Python3.8
41 0
|
1天前
|
并行计算 Ubuntu Docker
Docker环境Ubuntu20.04安装Python3.10版本
Docker环境Ubuntu20.04安装Python3.10版本
14 0
|
1天前
|
Python Windows
Python分发包安装pip3
Python分发包安装pip3
6 0
|
1天前
|
Web App开发 测试技术 Python
【如何学习python自动化测试】—— 浏览器驱动的安装 以及 如何更新driver
【如何学习python自动化测试】—— 浏览器驱动的安装 以及 如何更新driver
8 0
|
1天前
|
Web App开发 测试技术 C++
Playwright安装与Python集成:探索跨浏览器测试的奇妙世界
Playwright是新兴的跨浏览器测试工具,相比Selenium,它支持Chrome、Firefox、WebKit,执行速度快,选择器更稳定。安装Playwright只需一条`pip install playwright`的命令,随后的`playwright install`会自动添加浏览器,无需处理浏览器驱动问题。这一优势免去了Selenium中匹配驱动的烦恼。文章适合寻求高效自动化测试解决方案的开发者。
14 2
|
1天前
|
关系型数据库 MySQL 数据库
Python Stock安装与使用
Python Stock安装与使用
|
1天前
|
Shell 数据安全/隐私保护 Docker
docker安装anaconda3 python环境
docker安装anaconda3 python环境
11 0
|
1天前
|
数据采集 iOS开发 MacOS
Python及Pycharm安装教程
Python及Pycharm安装教程
26 0
|
1天前
|
开发者 Python
使用Python构建Web应用的简介
【4月更文挑战第28天】
|
1天前
|
Linux Python Windows
Python虚拟环境virtualenv安装保姆级教程(Windows和linux)
Python虚拟环境virtualenv安装保姆级教程(Windows和linux)