Python数据科学利器

2023-06-25,,

每个工具都带有用来创造它的那种精神。 —— 海森堡《物理学和哲学》

Anaconda

Anaconda是一个python的科学计算发行版,其附带了一大批常用的数据科学包,不用再使用pip安装数据科学包,再也不用为各种数据科学包版本和依赖冲突发愁了,哈哈。

conda

conda和pip类似,conda专注数据科学包,且不仅仅用于安装python包,而pip为python量身定制的,应用更广泛。

conda命令:

usage: conda [-h] [-V] command ...

conda is a tool for managing and deploying applications, environments and packages.

Options:

positional arguments:
command
clean Remove unused packages and caches.
config Modify configuration values in .condarc. This is modeled
after the git config command. Writes to the user .condarc
file (/Users/lihua/.condarc) by default.
create Create a new conda environment from a list of specified
packages.
help Displays a list of available conda commands and their help
strings.
info Display information about current conda install.
init Initialize conda for shell interaction. [Experimental]
install Installs a list of packages into a specified conda
environment.
list List linked packages in a conda environment.
package Low-level conda package utility. (EXPERIMENTAL)
remove Remove a list of packages from a specified conda environment.
uninstall Alias for conda remove.
run Run an executable in a conda environment. [Experimental]
search Search for packages and display associated information. The
input is a MatchSpec, a query language for conda packages.
See examples below.
update Updates conda packages to the latest compatible version.
upgrade Alias for conda update. optional arguments:
-h, --help Show this help message and exit.
-V, --version Show the conda version number and exit. conda commands available from other packages:
build
convert
debug
develop
env
index
inspect
metapackage
render
server
skeleton
verify

上面每个命令已经说的很详细了,常用的命令如下:

搜索包:

conda search package_name

安装包:

conda install package_name

注意安装的时候,conda会自动安装依赖项。例如:pandas依赖numpy,使用命令conda install pandas时会自动安装numpy。还可以安装指定版本,如conda install pandas=0.24.2

卸载包:

conda remove package_name

更新包:

conda update package_name

更新所有包:

conda update --all

列出当前已安装的包:

conda list

列出当前存在的虚拟环境:

conda env list

Install

对于不同的操作系统下载不同的环境,这里以MacOS为例。

有图形化界面安装和命令行安装,图形化安装下载.pkg结尾的包,双击按照提示步骤安装就行,这里主要说一下命令行安装方式。

使用命令行安装

1.下载包链接

https://www.anaconda.com/distribution/#macos

下载完是.sh结尾的shell文件。这里使用python3,因为python2官方会在2020年停止支持。

2.在mac终端中使用命令:

bash ~/Downloads/Anaconda3-2019.07-MacOSX-x86_64.sh

3.安装程序提示“为了继续安装过程,请查看许可协议。”单击Enter查看许可条款。滚动到许可条款到底部,并输入yes同意条款。

4.确认安装路径。

5.安装程序提示Do you wish the installer to initialize Anaconda3 by running conda init?回答“是”。

6.安装过程显示Thank you for installing Anaconda!

7.配置环境变量,vi ~/.bash_profile

export PYTHON3_HOME=/Users/lihua/anaconda3
export PATH=$PATH:$PYTHON3_HOME/bin

上面PYTHON3_HOME为具体安装路径,配置完保存退出,使环境变量生效source ~/.bash_profile

8.然后就可以直接执行python命令进入了。

各种科学包,和以前写的一些关于这些包的简单使用博客链接。

Numpy:用于科学计算的包,简单操作

Scipy:用于数学,科学工程的软件

Matplotlib:2D绘图库,可绘制高质量的图片,简单操作

Pandas:提供高性能,易于使用的数据结构和数据分析工具,简单操作

jupyter-notebook

Anaconda自带了jupyter-notebook,可以让你在网页上交互式的写代码,类似于Apache Zeppelin。

配置好环境变量后,只需敲如下命令,就可进入界面:

jupyter-notebook

具体页面操作,可以自己体验体验,很简单。

Python数据科学利器的相关教程结束。

《Python数据科学利器.doc》

下载本文的Word格式文档,以方便收藏与打印。