《對比Excel,輕鬆學習Python數據分析》是一部由張俊紅所著書籍,出版發行。
基本介紹
- 書名:對比Excel,輕鬆學習Python數據分析
- 作者:張俊紅
- ISBN:9787121357930
- 出版社:電子工業出版社
書籍信息,內容簡介,目錄,
書籍信息
作譯者:張俊紅
出版時間:2019-01
千 字 數:369
版次:01-01
頁 數:284
開本:16開
裝幀:平裝
I S B N :9787121357930
定價:¥59.0
內容簡介
本書通過對比Excel 功能操作去學習Python 的實現代碼,而不是直接上來就學習Python代碼,大大降低了學習門檻,消除了讀者對代碼的恐懼心理。適合剛入行的數據分析師,也適合對Excel 比較熟練的數據分析師,或從事其他崗位想提高工作效率的職場人。
目錄
入門篇
第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
第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