环境配置及基础实操 一:下载、安装 Python 二:下载、安装 Anaconda 三:新建开发环境、安装 Jupyter notebook 新建开发环境
创建新环境:conda create -n env_name
激活新环境:conda active env_name
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 (base) C:\Users\lenovo>conda create -n imooc_ai Collecting package metadata (current_repodata.json): done Solving environment: done environment location: Y:\SoftWare\anaconda\Anaconda3\envs\imooc_ai Proceed ([y]/n)? y Preparing transaction: done Verifying transaction: done Executing transaction: done Retrieving notices: ...working... done (base) C:\Users\lenovo>conda activate imooc_ai
四:Jupyter notebook 界面优化 借助开源项目,对界面进行优化,
项目地址:https://github.com/dunovank/jupyter-themes
Install with pip 1 2 3 4 5 pip install jupyterthemes pip install --upgrade jupyterthemes
配置 1 jt -t grade3 -f fira -fs 16 -cellw 90% -ofs 11 -dfs 11 -T
五:Python 语法实操 1 2 3 4 5 6 a = 1 b = 2 print (a,b)1 2
1 2 3 4 a = [1 ,2 ,3 ,4 ] print (type (a),a)<class 'list' > [1 , 2 , 3 , 4 ]
1 2 3 4 b = [x+10 for x in a] print (type (b),b)<class 'list' > [11 , 12 , 13 , 14 ]
1 2 3 4 def plusFunction (x1,x2 ): x = x1 + x2 return x
1 2 3 4 5 6 a = 1 b = 2 c = plusFunction(a,b) print (type (c),c)<class 'int' > 3
1 2 3 4 5 6 import randomm = random.random() print (m)0.21730372821275368
1 2 3 4 5 6 7 8 9 10 11 12 13 14 for i in [1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ]: m_i = random.random() print (m_i) 0.22372759310304402 0.15114745033159727 0.18443572156105592 0.8748129421654894 0.532564243518567 0.27301908385530627 0.3783824153668166 0.7295293943105771 0.1718886842112275 0.45445079430510904
六:Matplotlib 实操 1 2 3 4 5 6 import matplotlibx = [1 ,2 ,3 ,4 ,5 ] y = [2 ,3 ,4 ,5 ,6 ] print (x,y)[1 , 2 , 3 , 4 , 5 ] [2 , 3 , 4 , 5 , 6 ]
1 2 3 4 from matplotlib import pyplot as pltfig1 = plt.figure(figsize=(5 ,5 )) plt.plot(x,y) plt.show()
1 2 3 4 5 6 fig2 = plt.figure(figsize=(5 ,5 )) plt.scatter(x,y) plt.title("x vs y" ) plt.xlabel("x" ) plt.ylabel("y" ) plt.show()
七:Numpy 实操 1 2 3 4 5 6 7 8 9 10 11 import numpy as npa = np.eye(5 ) print (type (a))print (a)<class 'numpy.ndarray' > [[1. 0. 0. 0. 0. ] [0. 1. 0. 0. 0. ] [0. 0. 1. 0. 0. ] [0. 0. 0. 1. 0. ] [0. 0. 0. 0. 1. ]]
1 2 3 4 5 6 7 8 9 10 11 12 b = np.ones([5 ,5 ]) print (type (b))print (b)print (b.shape)<class 'numpy.ndarray' > [[1. 1. 1. 1. 1. ] [1. 1. 1. 1. 1. ] [1. 1. 1. 1. 1. ] [1. 1. 1. 1. 1. ] [1. 1. 1. 1. 1. ]] (5 , 5 )
1 2 3 4 5 6 7 8 9 10 11 12 c = a + b print (type (c))print (c.shape)print (c)<class 'numpy.ndarray' > (5 , 5 ) [[2. 1. 1. 1. 1. ] [1. 2. 1. 1. 1. ] [1. 1. 2. 1. 1. ] [1. 1. 1. 2. 1. ] [1. 1. 1. 1. 2. ]]
八:Pandas 实操 1 2 3 4 5 6 7 8 9 10 11 import pandas as pddata = pd.read_csv("Y:\\temp\\data\\date.csv" ) print (type (data))print (data)<class 'pandas.core.frame.DataFrame' > x y 0 1 2 1 2 3 2 3 4 3 5 4
1 2 3 4 5 6 7 8 9 10 11 x = data.loc[:,'x' ] print (type (x))y = data.loc[:,'y' ] print (y)<class 'pandas.core.series.Series' > 0 2 1 3 2 4 3 4 Name: y, dtype: int64
1 2 3 4 5 6 c = data.loc[:,'x' ][y>3 ] print (c)2 3 3 5 Name: x, dtype: int64
1 2 3 4 5 6 7 8 9 data_array = np.array(data) print (type (data_array))print (data_array)<class 'numpy.ndarray' > [[1 2 ] [2 3 ] [3 4 ] [5 4 ]]
1 2 3 4 5 6 7 8 9 data_new = data + 10 data_new.head() x y 0 11 12 1 12 13 2 13 14 3 15 14
1 2 data_new.to_csv('Y:\\temp\\data\\data.csv' )