入門篇
第1章數據分析基礎.............................................................................................2
1.1數據分析是什麼............................................................................................2
1.2為什麼要做數據分析....................................................................................2
1.2.1現狀分析.............................................................................................3
1.2.2原因分析.............................................................................................3
1.2.3預測分析.............................................................................................3
1.3數據分析究竟在分析什麼............................................................................4
1.3.1總體概覽指標.....................................................................................4
1.3.2對比性指標.........................................................................................4
1.3.3集中趨勢指標.....................................................................................4
1.3.4離散程度指標.....................................................................................5
1.3.5相關性指標.........................................................................................5
1.3.6相關關係與因果關係.........................................................................6
1.4數據分析的常規流程....................................................................................6
1.4.1熟悉工具.............................................................................................6
1.4.2明確目的.............................................................................................7
1.4.3獲取數據.............................................................................................7
1.4.4熟悉數據.............................................................................................7
1.4.5處理數據.............................................................................................7
1.4.6分析數據.............................................................................................8
1.4.7得齣結論.............................................................................................8
1.4.8驗證結論.............................................................................................8
1.4.9展示結論.............................................................................................8
1.5數據分析工具:Excel與Python..................................................................8
實踐篇
第2章熟悉鍋——Python基礎知識.....................................................................12
2.1Python是什麼..............................................................................................12
2.2Python的下載與安裝..................................................................................13
2.2.1安裝教程...........................................................................................13
2.2.2IDE與IDLE.....................................................................................17
2.3介紹JupyterNotebook................................................................................17
2.3.1新建JupyterNotebook文件............................................................17
2.3.2運行你的第一段代碼.......................................................................19
2.3.3重命名JupyterNotebook文件........................................................19
2.3.4保存JupyterNotebook文件............................................................19
2.3.5導入本地JupyterNotebook文件....................................................20
2.3.6JupyterNotebook與Markdown.......................................................21
2.3.7為JupyterNotebook添加目錄........................................................21
2.4基本概念......................................................................................................26
2.4.1數.......................................................................................................26
2.4.2變量...................................................................................................26
2.4.3標識符...............................................................................................27
2.4.4數據類型...........................................................................................28
2.4.5輸齣與輸齣格式設置.......................................................................28
2.4.6縮進與注釋.......................................................................................29
2.5字符串..........................................................................................................30
2.5.1字符串的概念...................................................................................30
2.5.2字符串的連接...................................................................................30
2.5.3字符串的復製...................................................................................30
2.5.4獲取字符串的長度...........................................................................30
2.5.5字符串查找.......................................................................................31
2.5.6字符串索引.......................................................................................31
2.5.7字符串分隔.......................................................................................32
2.5.8移除字符...........................................................................................32
2.6數據結構——列錶......................................................................................33
2.6.1列錶的概念.......................................................................................33
2.6.2新建一個列錶...................................................................................33
2.6.3列錶的復製.......................................................................................34
2.6.4列錶的閤並.......................................................................................34
2.6.5嚮列錶中插入新元素.......................................................................34
2.6.6獲取列錶中值齣現的次數...............................................................35
2.6.7獲取列錶中值齣現的位置...............................................................35
2.6.8獲取列錶中指定位置的值...............................................................36
2.6.9刪除列錶中的值...............................................................................36
2.6.10對列錶中的值進行排序.................................................................37
2.7數據結構——字典......................................................................................37
2.7.1字典的概念.......................................................................................37
2.7.2新建一個字典...................................................................................37
2.7.3字典的keys()、values()和items()方法...........................................37
2.8數據結構——元組......................................................................................38
2.8.1元組的概念.......................................................................................38
2.8.2新建一個元組...................................................................................38
2.8.3獲取元組的長度...............................................................................38
2.8.4獲取元組內的元素...........................................................................39
2.8.5元組與列錶相互轉換.......................................................................39
2.8.6zip()函數...........................................................................................39
2.9運算符..........................................................................................................40
2.9.1算術運算符.......................................................................................40
2.9.2比較運算符.......................................................................................40
2.9.3邏輯運算符.......................................................................................41
2.10循環語句....................................................................................................41
2.10.1for循環...........................................................................................41
2.10.2while循環.......................................................................................42
2.11條件語句....................................................................................................43
2.11.1if語句.............................................................................................43
2.11.2else語句..........................................................................................44
2.11.3elif語句..........................................................................................45
2.12函數............................................................................................................46
2.12.1普通函數.........................................................................................47
2.12.2匿名函數.........................................................................................48
2.13高級特性....................................................................................................49
2.13.1列錶生成式.....................................................................................49
2.13.2map函數.........................................................................................50
2.14模塊............................................................................................................50
第3章Pandas數據結構.....................................................................................51
3.1Series數據結構...........................................................................................51
3.1.1Series是什麼....................................................................................51
3.1.2創建一個Series................................................................................52
3.1.3利用index方法獲取Series的索引................................................53
3.1.4利用values方法獲取Series的值...................................................53
3.2DataFrame錶格型數據結構.......................................................................53
3.2.1DataFrame是什麼............................................................................53
3.2.2創建一個DataFrame........................................................................54
3.2.3獲取DataFrame的行、列索引.......................................................56
3.2.4獲取DataFrame的值.......................................................................56
第4章準備食材——獲取數據源..........................................................................57
4.1導入外部數據..............................................................................................57
4.1.1導入.xlsx文件..................................................................................57
4.1.2導入.csv文件...................................................................................60
4.1.3導入.txt文件....................................................................................63
4.1.4導入sql文件....................................................................................65
4.2新建數據......................................................................................................67
4.3熟悉數據......................................................................................................67
4.3.1利用head預覽前幾行.....................................................................67
4.3.2利用shape獲取數據錶的大小........................................................68
4.3.3利用info獲取數據類型..................................................................69
4.3.4利用describe獲取數值分布情況....................................................71
第5章淘米洗菜——數據預處理..........................................................................73
5.1缺失值處理..................................................................................................73
5.1.1缺失值查看.......................................................................................73
5.1.2缺失值刪除.......................................................................................75
5.1.3缺失值填充.......................................................................................77
5.2重復值處理..................................................................................................78
5.3異常值的檢測與處理..................................................................................81
5.3.1異常值檢測.......................................................................................81
5.3.2異常值處理.......................................................................................82
5.4數據類型轉換..............................................................................................83
5.4.1數據類型...........................................................................................83
5.4.2類型轉換...........................................................................................84
5.5索引設置......................................................................................................86
5.5.1為無索引錶添加索引.......................................................................86
5.5.2重新設置索引...................................................................................87
5.5.3重命名索引.......................................................................................88
5.5.4重置索引...........................................................................................89
第6章菜品挑選——數據選擇.............................................................................91
6.1列選擇..........................................................................................................91
6.1.1選擇某一列/某幾列..........................................................................91
6.1.2選擇連續的某幾列...........................................................................92
6.2行選擇..........................................................................................................93
6.2.1選擇某一行/某幾行..........................................................................93
6.2.2選擇連續的某幾行...........................................................................94
6.2.3選擇滿足條件的行...........................................................................95
6.3行列同時選擇..............................................................................................96
6.3.1普通索引+普通索引選擇指定的行和列.........................................97
6.3.2位置索引+位置索引選擇指定的行和列.........................................97
6.3.3布爾索引+普通索引選擇指定的行和列.........................................98
6.3.4切片索引+切片索引選擇指定的行和列.........................................98
6.3.5切片索引+普通索引選擇指定的行和列.........................................99
第7章切配菜品——數值操作...........................................................................100
7.1數值替換....................................................................................................100
7.1.1一對一替換.....................................................................................100
7.1.2多對一替換.....................................................................................102
7.1.3多對多替換.....................................................................................103
7.2數值排序....................................................................................................104
7.2.1按照一列數值進行排序.................................................................104
7.2.2按照有缺失值的列進行排序.........................................................106
7.2.3按照多列數值進行排序.................................................................106
7.3數值排名....................................................................................................108
7.4數值刪除.....................................................................................................110
7.4.1刪除列..............................................................................................110
7.4.2刪除行..............................................................................................111
7.4.3刪除特定行......................................................................................112
7.5數值計數.....................................................................................................113
7.6唯一值獲取.................................................................................................114
7.7數值查找.....................................................................................................115
7.8區間切分.....................................................................................................116
7.9插入新的行或列.........................................................................................119
7.10行列互換..................................................................................................120
7.11索引重塑..................................................................................................121
7.12長寬錶轉換..............................................................................................122
7.12.1寬錶轉換為長錶...........................................................................123
7.12.2長錶轉換為寬錶...........................................................................125
7.13apply()與applymap()函數.......................................................................126
第8章開始烹調——數據運算...........................................................................127
8.1算術運算....................................................................................................127
8.2比較運算....................................................................................................128
8.3匯總運算....................................................................................................129
8.3.1count非空值計數...........................................................................129
8.3.2sum求和.........................................................................................130
8.3.3mean求均值...................................................................................130
8.3.4max求最大值.................................................................................131
8.3.5min求最小值.................................................................................132
8.3.6median求中位數............................................................................132
8.3.7mode求眾數...................................................................................133
8.3.8var求方差.......................................................................................134
8.3.9std求標準差...................................................................................134
8.3.10quantile求分位數.........................................................................135
8.4相關性運算................................................................................................136
第9章炒菜計時器——時間序列........................................................................138
9.1獲取當前時刻的時間................................................................................138
9.1.1返迴當前時刻的日期和時間.........................................................138
9.1.2分彆返迴當前時刻的年、月、日.................................................138
9.1.3返迴當前時刻的周數.....................................................................139
9.2指定日期和時間的格式............................................................................140
9.3字符串和時間格式相互轉換....................................................................141
9.3.1將時間格式轉換為字符串格式.....................................................141
9.3.2將字符串格式轉換為時間格式.....................................................141
9.4時間索引....................................................................................................142
9.5時間運算....................................................................................................145
9.5.1兩個時間之差.................................................................................145
9.5.2時間偏移.........................................................................................145
第10章菜品分類——數據分組/數據透視錶......................................................148
10.1數據分組..................................................................................................148
10.1.1分組鍵是列名...............................................................................150
10.1.2分組鍵是Series............................................................................151
10.1.3神奇的aggregate方法.................................................................152
10.1.4對分組後的結果重置索引...........................................................153
10.2數據透視錶..............................................................................................154
第11章水果拼盤——多錶拼接.........................................................................158
11.1錶的橫嚮拼接..........................................................................................158
11.1.1連接錶的類型...............................................................................158
11.1.2連接鍵的類型...............................................................................160
11.1.3連接方式.......................................................................................163
11.1.4重復列名處理...............................................................................165
11.2錶的縱嚮拼接..........................................................................................165
11.2.1普通閤並.......................................................................................166
11.2.2索引設置.......................................................................................167
11.2.3重疊數據閤並...............................................................................167
第12章盛菜裝盤——結果導齣.........................................................................169
12.1導齣為.xlsx文件.....................................................................................169
12.1.1設置文件導齣路徑.......................................................................170
12.1.2設置Sheet名稱............................................................................170
12.1.3設置索引.......................................................................................170
12.1.4設置要導齣的列...........................................................................171
12.1.5設置編碼格式...............................................................................171
12.1.6缺失值處理...................................................................................172
12.1.7無窮值處理...................................................................................172
12.2導齣為.csv文件.......................................................................................173
12.2.1設置文件導齣路徑.......................................................................173
12.2.2設置索引.......................................................................................174
12.2.3設置要導齣的列...........................................................................174
12.2.4設置分隔符號...............................................................................174
12.2.5缺失值處理...................................................................................174
12.2.6設置編碼格式...............................................................................175
12.3將文件導齣到多個Sheet........................................................................175
第13章菜品擺放——數據可視化......................................................................176
13.1數據可視化是什麼..................................................................................176
13.2數據可視化的基本流程..........................................................................176
13.2.1整理數據.......................................................................................176
13.2.2明確目的.......................................................................................177
13.2.3尋找閤適的錶現形式...................................................................177
13.3圖錶的基本組成元素..............................................................................177
13.4Excel與Python可視化...........................................................................179
13.5建立畫布和坐標係..................................................................................179
13.5.1建立畫布.......................................................................................179
13.5.2用add_subplot函數建立坐標係.................................................180
13.5.3用plt.subplot2grid函數建立坐標係............................................182
13.5.4用plt.subplot函數建立坐標係....................................................183
13.5.5用plt.subplots函數建立坐標係..................................................184
13.5.6幾種創建坐標係方法的區彆.......................................................185
13.6設置坐標軸..............................................................................................185
13.6.1設置坐標軸的標題.......................................................................185
13.6.2設置坐標軸的刻度.......................................................................187
13.6.3設置坐標軸的範圍.......................................................................190
13.6.4坐標軸的軸顯示設置...................................................................191
13.7其他圖錶格式的設置..............................................................................191
13.7.1網格綫設置...................................................................................191
13.7.2設置圖例.......................................................................................193
13.7.3圖錶標題設置...............................................................................195
13.7.4設置數據標簽...............................................................................197
13.7.5圖錶注釋.......................................................................................198
13.7.6數據錶...........................................................................................199
13.8繪製常用圖錶..........................................................................................201
13.8.1繪製摺綫圖...................................................................................201
13.8.2繪製柱形圖...................................................................................204
13.8.3繪製條形圖...................................................................................208
13.8.4繪製散點圖...................................................................................209
13.8.5繪製氣泡圖....................................................................................211
13.8.6繪製麵積圖...................................................................................212
13.8.7繪製樹地圖...................................................................................213
13.8.8繪製雷達圖...................................................................................215
13.8.9繪製箱形圖...................................................................................217
13.8.10繪製餅圖.....................................................................................218
13.8.11繪製圓環圖.................................................................................220
13.8.12繪製熱力圖.................................................................................221
13.8.13繪製水平綫和垂直綫.................................................................223
13.9繪製組閤圖錶..........................................................................................224
13.9.1摺綫圖+摺綫圖............................................................................224
13.9.2摺綫圖+柱形圖............................................................................225
13.10繪製雙坐標軸圖錶................................................................................226
13.10.1繪製雙y軸圖錶.........................................................................227
13.10.2繪製雙x軸圖錶.........................................................................228
13.11繪圖樣式設置........................................................................................228
進階篇
第14章典型數據分析案例................................................................................234
14.1利用Python實現報錶自動化.................................................................234
14.1.1為什麼要進行報錶自動化...........................................................234
14.1.2什麼樣的報錶適閤自動化...........................................................234
14.1.3如何實現報錶自動化...................................................................235
14.2自動發送電子郵件..................................................................................239
14.3假如你是某連鎖超市的數據分析師......................................................241
14.3.1哪些類彆的商品比較暢銷...........................................................242
14.3.2哪些商品比較暢銷.......................................................................242
14.3.3不同門店的銷售額占比...............................................................243
14.3.4哪些時間段是超市的客流高峰期...............................................244
14.4假如你是某銀行的數據分析師..............................................................245
14.4.1是不是收入越高的人壞賬率越低...............................................246
14.4.2年齡和壞賬率有什麼關係...........................................................247
14.4.3傢庭人口數量和壞賬率有什麼關係...........................................248
第15章NumPy數組.........................................................................................250
15.1NumPy簡介.............................................................................................250
15.2NumPy數組的生成.................................................................................250
15.2.1生成一般數組...............................................................................251
15.2.2生成特殊類型數組.......................................................................251
15.2.3生成隨機數組...............................................................................253
15.3NumPy數組的基本屬性.........................................................................255
15.4NumPy數組的數據選取.........................................................................256
15.4.1一維數據選取...............................................................................256
15.4.2多維數據選取...............................................................................257
15.5NumPy數組的數據預處理.....................................................................259
15.5.1NumPy數組的類型轉換..............................................................259
15.5.2NumPy數組的缺失值處理..........................................................260
15.5.3NumPy數組的重復值處理..........................................................260
15.6NumPy數組重塑.....................................................................................261
15.6.1一維數組重塑...............................................................................261
15.6.2多維數組重塑...............................................................................261
15.6.3數組轉置.......................................................................................262
15.7NumPy數組閤並.....................................................................................262
15.7.1橫嚮閤並.......................................................................................262
15.7.2縱嚮閤並.......................................................................................263
15.8常用數據分析函數..................................................................................264
15.8.1元素級函數...................................................................................264
15.8.2描述統計函數...............................................................................264
15.8.3條件函數.......................................................................................266
15.8.4集閤關係.......................................................................................266
· · · · · · (
收起)