工具篇:命令行里的數(shù)據(jù)科學(xué)工具
@(數(shù)據(jù)科學(xué))[小樹枝來了, 幫助, Markdown, 數(shù)據(jù)分析]
- 環(huán)境配置
- 安裝anaconda
- 虛擬環(huán)境管理工具
注意:請將conda放在PATH里(一般來說,安裝了anaconda之后,conda會默認(rèn)放入path)
for windows user
C:\Users\Admin\Anaconda3\Scriptsfor linux or mac user
export PATH="/xxx/anaconda/bin:$PATH"C:\Users\Admin\Anaconda3\envs
創(chuàng)建新的虛擬環(huán)境:
- conda create -n env_name python=2.7
虛擬環(huán)境查看:
- conda env list
- conda env remove -n env_name
- conda create -n env_name python=3 numpy scipy
- activate env_name
- deactivate env_name
安裝工具:
- conda list
- conda install numpy
- conda remove numpy
- conda update numpy
- conda search xxx
加速:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
conda config --show
刪除channels:
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
Cmd,cd進入目標(biāo)目錄,然后git clone remote.github.url
git clone https://github.com/jvns/pandas-cookbook
新建代碼庫
- 在當(dāng)前目錄新建一個Git代碼庫
$ git init
- 新建一個目錄,將其初始化為Git代碼庫
$ git init [project-name] - 下載一個項目和它的整個代碼歷史
$ git clone [url]
Git上傳代碼:
https://github.com/henry-li/hello-world.git
We recommend every repository include a README, LICENSE, and .gitignore.
…or create a new repository on the command line
echo "- hello-world" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/henry-li/hello-world.git
git push -u origin master
…or push an existing repository from the command line
git remote add origin https://github.com/henry-li/hello-world.git
git push -u origin master
…or import code from another repository
You can initialize this repository with code from a Subversion, Mercurial, or TFS project.
tips:
Markdown和In的轉(zhuǎn)換: 先esc,M和Y切換,Ctrl+enter顯示
正則表達(dá)式
正則表達(dá)式的常用縮寫字符:
\d:0-9任何數(shù)字
\D:0-9之外的任何字符
\w:任何字母、數(shù)字、下劃線(可以認(rèn)為是匹配單詞,word)
\W:除了任何字符、數(shù)字、下劃線
\s:空格、制表符或者換行符(可以認(rèn)為是空白,space)
\S:除了空白字符之外
[]:[0-5] or (0|1|2|3|4|5)
+:1個至多個字符
常用正則表達(dá)式:
### re模塊的主要方法:
### search():找到符合的那個模式的信息
### findall():找到所有符合模式的信息
### sub():找到符合模式的信息并且替換
利用()分組
利用轉(zhuǎn)義字符避免()分組帶來的問題
利用 | 匹配多個分組
利用 ?實現(xiàn)選擇匹配(有或沒有)
利用 * 進行匹配(零次或多次)
利用 + 進行匹配(一次或多次)
利用 {} 匹配特定次數(shù)
正則表達(dá)式的findall()方法
# 自定義的字符模式
# [abc] a or b or c
# [] 無需轉(zhuǎn)義
# [] ^取非 [^]
正則表達(dá)式的^和 $ 的使用
#?!號
# “不包含”字符
#.號通配符
# 只匹配一個字符,**匹配除換行**之外的所有字符
#比如用.*匹配所有字符,
# 添加注釋
phoneRegex = re.compile(r'''(
\d{3} # 注釋
(\s)
\d{4}
)''', re.VERBOSE)
phoneRegex.search('111 2222').group()
# email匹配
emailRegex = re.compile(r'''(
\w+ # 用戶名
@ # @符號
[a-zA-Z]+ # 域名
(\.[a-zA-Z]{2,4}) # 域名后面的字符
)''', re.VERBOSE)
emailRegex.search('jack@sina.com').group()

image.png