關(guān)于我們
書單推薦
新書推薦
|
Python數(shù)據(jù)分析與可視化應(yīng)用 讀者對(duì)象:本書適合作為高等學(xué)校計(jì)算機(jī)科學(xué)與技術(shù)、人工智能、大數(shù)據(jù)等相關(guān)專業(yè)Python 課程的教材,也適合對(duì)Python 感興趣或擬使用Python 進(jìn)行數(shù)據(jù)分析和可視化展示的讀者參考。
本書結(jié)合作者多年工程和實(shí)踐經(jīng)驗(yàn),從Python 基礎(chǔ)編程語法入手,系統(tǒng)介紹了基于Python 語言進(jìn)行數(shù)據(jù)處理、分析與可視化展示所需的各項(xiàng)知識(shí)和技術(shù)。讀者無須特別的數(shù)學(xué)或統(tǒng)計(jì)方面的理論知識(shí),只需理解數(shù)據(jù)分析的思路,就可以參考示例學(xué)會(huì)針對(duì)實(shí)際問題進(jìn)行有效數(shù)據(jù)分析的步驟和方法。 本書分4 篇共20 章,主要內(nèi)容涉及Python 基本語法、程序控制結(jié)構(gòu)、函數(shù)、面向?qū)ο蠡A(chǔ)、文件操作、標(biāo)準(zhǔn)庫、正則表達(dá)式、numpy 庫、pandas 庫、數(shù)據(jù)預(yù)處理、matplotlib 可視化圖表、seaborn可視化圖表、pyecharts 可視化圖表、SciPy 科學(xué)計(jì)算、共享自行車案例及在線銷售案例。
唐藝,助理研究員,長(zhǎng)期從事計(jì)算機(jī)應(yīng)用、信息系統(tǒng)的教學(xué)與科研工作,作為課題負(fù)責(zé)人申報(bào)省部級(jí)課題10余項(xiàng)。
第一篇 Python 基礎(chǔ)
第1 章 Python 概述 ······················.2 1.1 Python 簡(jiǎn)介 ······························.2 1.1.1 Python 的起源 ··················.2 1.1.2 Python 的發(fā)展 ··················.2 1.2 Python 解釋器 ···························.3 1.2.1 安裝Python 解釋器 ···········.3 1.2.2 交互運(yùn)行模式 ··················.4 1.2.3 命令行運(yùn)行模式 ···············.4 1.3 集成開發(fā)環(huán)境PyCharm ················.5 1.3.1 安裝PyCharm ··················.5 1.3.2 創(chuàng)建項(xiàng)目 ························.7 1.3.3 創(chuàng)建并運(yùn)行Python 文件 ·····.8 第2 章 Python 編程基礎(chǔ) ················10 2.1 常量和變量 ·······························10 2.1.1 常量和變量的定義 ············10 2.1.2 變量命名規(guī)則 ··················10 2.2 簡(jiǎn)單數(shù)據(jù)類型 ···························.11 2.2.1 數(shù)值類型 ·······················.11 2.2.2 字符串 ···························12 2.2.3 None ·····························13 2.2.4 布爾類型 ························14 2.2.5 數(shù)據(jù)類型轉(zhuǎn)換 ··················14 2.3 算術(shù)運(yùn)算 ··································15 2.4 賦值運(yùn)算符 ·······························16 2.5 字符串相關(guān)運(yùn)算 ·························17 2.5.1 字符串連接運(yùn)算 ···············17 2.5.2 字符串截取 ·····················18 2.6 輸出 ········································18 2.6.1 print 函數(shù)的基本用法 ········19 2.6.2 print 函數(shù)格式化輸出 ········20 2.7 輸入 ········································23 2.8 程序注釋 ··································23 第3 章 程序控制結(jié)構(gòu) ····················25 3.1 選擇結(jié)構(gòu) ··································25 3.1.1 條件表達(dá)式 ·····················25 3.1.2 單分支結(jié)構(gòu)if 語句············27 3.1.3 二分支結(jié)構(gòu)if-else 語句 ······27 3.1.4 多分支結(jié)構(gòu)if-elif-else語句 ······························29 3.2 循環(huán)結(jié)構(gòu) ··································31 3.2.1 for 語句實(shí)現(xiàn)遍歷循環(huán) ········31 3.2.2 while 語句實(shí)現(xiàn)條件循環(huán) ····33 3.2.3 循環(huán)結(jié)構(gòu)中的else 語句 ······35 3.2.4 break 語句和continue語句 ······························36 第4 章 組合數(shù)據(jù)類型 ····················39 4.1 列表 ········································39 4.1.1 列表的表示與訪問列表元素 ······························39 4.1.2 遍歷列表 ························40 4.1.3 添加列表元素 ··················42 4.1.4 刪除列表元素 ··················44 4.1.5 列表排序 ························45 4.2 元組 ········································46 4.3 字典 ········································47 4.3.1 創(chuàng)建字典 ························48 4.3.2 添加和刪除鍵值對(duì) ············49 4.3.4 遍歷字典 ························49 4.3.5 字典嵌套 ························50 第5 章 函數(shù) ································52 5.1 函數(shù)的定義和調(diào)用 ······················52 5.2 函數(shù)參數(shù)傳遞 ····························54 5.3 列表作為函數(shù)參數(shù) ······················57 5.3.1 簡(jiǎn)單數(shù)據(jù)類型參數(shù)傳遞值 ···························57 5.3.2 組合數(shù)據(jù)類型參數(shù)公用存儲(chǔ)空間 ··················57 5.3.3 組合數(shù)據(jù)類型的數(shù)據(jù)作為函數(shù)參數(shù)的應(yīng)用 ·········58 5.4 模塊 ········································59 5.4.1 創(chuàng)建模塊 ························59 5.4.2 導(dǎo)入模塊 ························60 第6 章 類和對(duì)象 ··························63 6.1 類和對(duì)象的概念 ·························63 6.2 定義只具有方法的類和對(duì)象 ··········64 6.2.1 定義類 ···························64 6.2.2 實(shí)例化對(duì)象 ·····················65 6.3 對(duì)象初始化方法及屬性 ················66 6.3.1 對(duì)象初始化方法_ _init_ _() ······················66 6.3.2 定義類的屬性 ··················66 6.3.3 訪問對(duì)象屬性 ··················67 6.3.4 輸出對(duì)象的描述信息 ·········68 6.3.5 封裝性 ···························69 6.4 類和對(duì)象應(yīng)用實(shí)例 ······················69 6.5 類的繼承 ··································70 6.5.1 繼承的定義 ·····················70 6.5.2 _init_ _() 方法的繼承 ·······72 6.5.3 重寫父類方法 ··················73 第7 章 文件操作 ··························74 7.1 基本操作 ··································74 7.2 打開文件 ··································75 7.2.1 文件指針 ························75 7.2.2 打開方式 ························76 7.3 讀取文件 ··································77 7.4 寫入文件 ··································78 7.4.1 使用write() 方法向文件中寫入內(nèi)容 ························78 7.4.2 使用write() 方法向文件中追加內(nèi)容 ························79 7.5 讀寫CSV 文件 ··························80 7.5.1 讀取數(shù)據(jù) ························80 7.5.2 寫入數(shù)據(jù) ························81 第8 章 常用Python 標(biāo)準(zhǔn)庫 ············83 8.1 datetime 模塊 ·····························83 8.1.1 date 類 ···························83 8.1.2 time 類 ···························86 8.1.3 datetime 類 ······················86 8.1.4 timedelta 類 ·····················87 8.1.5 時(shí)間轉(zhuǎn)化 ························88 8.1.6 設(shè)置日期時(shí)間格式 ············88 8.2 math 模塊 ·································89 8.3 random 模塊 ······························90 8.4 os 模塊 ····································92 第二篇 數(shù) 據(jù) 分 析 第9 章 正則表達(dá)式 ·······················98 9.1 正則表達(dá)式中的元字符 ················98 9.1.1 主要元字符 ·····················98 9.1.2 對(duì)字符進(jìn)行轉(zhuǎn)義 ···············99 9.1.3 標(biāo)記開始與結(jié)束 ···············99 9.2 匹配一組字符 ·························.100 9.2.1 定義一組字符 ···············.100 9.2.2 對(duì)一組字符取反 ············.100 9.2.3 使用區(qū)間簡(jiǎn)化一組字符的定義 ···························.100 9.3 使用量詞進(jìn)行多次匹配 ·············.101 9.3.1 常用量詞 ·····················.101 9.3.2 貪婪和非貪婪匹配 ·········.101 9.3.3 分組 ···························.102 9.4 使用re 模塊處理正則表達(dá)式 ······.102 9.4.1 Python 正則表達(dá)式的語法 ···························.102 9.4.2 匹配字符串 ··················.102 9.4.3 替換字符串 ··················.106 9.4.4 分割字符串 ··················.107 第10 章 使用numpy 進(jìn)行數(shù)值計(jì)算 ·····························108 10.1 使用numpy 生成數(shù)組 ·············.108 10.1.1 常用數(shù)組生成函數(shù) ·······.108 10.1.2 ndarray 對(duì)象屬性 ·········.109 10.1.3 數(shù)組變換 ·····················110 10.1.4 numpy 的隨機(jī)數(shù)函數(shù) ······112 10.2 數(shù)組的索引和切片 ···················112 10.2.1 數(shù)組的索引 ··················112 10.2.2 數(shù)組的切片 ··················113 10.3 數(shù)組的運(yùn)算 ····························114 10.3.1 數(shù)組和標(biāo)量間的運(yùn)算 ······114 10.3.2 通用函數(shù) ·····················114 10.3.3 統(tǒng)計(jì)運(yùn)算 ·····················115 10.4 數(shù)組的存儲(chǔ)與讀取 ···················116 10.4.1 數(shù)組的存儲(chǔ) ··················116 10.4.2 數(shù)組的讀取 ··················116 第11 章 pandas 數(shù)據(jù)分析模塊 ·····.118 11.1 pandas 數(shù)據(jù)結(jié)構(gòu) ······················118 11.1.1 創(chuàng)建Series 數(shù)據(jù) ·············118 11.1.2 創(chuàng)建DataFrame 數(shù)據(jù) ·····.120 11.2 添加、修改和刪除數(shù)據(jù) ···········.121 11.2.1 添加數(shù)據(jù) ···················.122 11.2.2 修改數(shù)據(jù) ···················.123 11.2.3 刪除數(shù)據(jù) ···················.124 11.3 索引操作 ·····························.126 11.3.1 重設(shè)索引 ···················.126 11.3.2 將已有列設(shè)置為索引 ····.126 11.3.3 重新命名索引 ·············.127 11.3.4 層次化索引 ················.128 11.4 選取數(shù)據(jù) ·····························.130 11.4.1 Series 數(shù)據(jù)的選取 ········.130 11.4.2 DataFrame 數(shù)據(jù)的選取 ·························.131 11.5 數(shù)據(jù)運(yùn)算 ·····························.133 11.5.1 算術(shù)運(yùn)算 ···················.133 11.5.2 函數(shù)應(yīng)用和映射 ··········.134 11.5.3 匯總與統(tǒng)計(jì) ················.135 11.5.4 唯一值和值計(jì)數(shù) ··········.138 第12 章 使用pandas 獲取和寫入數(shù)據(jù) ·····························140 12.1 文本數(shù)據(jù)的讀取與存儲(chǔ) ···········.140 12.1.1 CSV 文件的讀取 ··········.140 12.1.2 TXT 文件的讀取 ··········.142 12.1.3 文本數(shù)據(jù)的存儲(chǔ) ··········.143 12.2 Excel 與JSON 數(shù)據(jù) ················.143 12.2.1 Excel 數(shù)據(jù) ··················.143 12.2.2 JSON 數(shù)據(jù) ·················.144 12.3 數(shù)據(jù)庫的讀取與寫入 ··············.145 12.3.1 SQLAlchemy 包的安裝和數(shù)據(jù)庫的鏈接 ·············.145 12.3.2 SQLite 數(shù)據(jù)庫寫入和讀取數(shù)據(jù) ·························.145 第13 章 數(shù)據(jù)預(yù)處理 ····················147 13.1 數(shù)據(jù)清洗 ·····························.147 13.1.1 處理缺失值 ················.147 13.1.2 刪除重復(fù)數(shù)據(jù) ·············.150 13.1.3 替換值 ······················.151 13.1.4 利用函數(shù)或映射進(jìn)行數(shù)據(jù)轉(zhuǎn)換 ···················.152 13.2 對(duì)數(shù)據(jù)進(jìn)行排序和排名 ···········.153 13.2.1 數(shù)據(jù)排序 ···················.153 13.2.2 數(shù)據(jù)排名 ···················.155 13.3 數(shù)據(jù)合并和重塑 ····················.156 13.3.1 數(shù)據(jù)合并 ···················.156 13.3.2 數(shù)據(jù)連接 ···················.157 13.3.3 數(shù)據(jù)轉(zhuǎn)置 ···················.159 13.4 字符串處理 ··························.159 13.4.1 字符串方法 ················.159 13.4.2 使用正則表達(dá)式 ··········.160 14.1 數(shù)據(jù)分組 ·····························.161 14.1.1 認(rèn)識(shí)GroupBy ·············.161 第14 章 數(shù)據(jù)的分組與聚合 ···········161 14.1.2 按照列名進(jìn)行分組 ·······.162 14.1.3 按照Series 數(shù)據(jù)進(jìn)行 分組 ·························.163 14.2 數(shù)據(jù)聚合 ·····························.164 14.2.1 聚合函數(shù) ···················.164 14.2.2 使用aggregate() 方法 進(jìn)行數(shù)據(jù)聚合 ·············.165 14.3 長(zhǎng)表變寬表 ··························.166 14.3.1 什么是長(zhǎng)表和寬表 ·······.166 14.3.2 使用pivot 函數(shù)將長(zhǎng)表變?yōu)閷挶?···················.167 14.3.3 使用pivot_table 函數(shù)進(jìn)行數(shù)據(jù)透視分析 ·······.167 第三篇 數(shù)據(jù)可視化 第15 章 使用matplotlib 可視化數(shù)據(jù) 170 15.1 創(chuàng)建圖表的基本方法 ··············.170 15.1.1 圖表的基本組成元素 ····.170 15.1.2 建立畫布和坐標(biāo)系 ·······.171 15.1.3 設(shè)置坐標(biāo)軸 ················.175 15.1.4 設(shè)置網(wǎng)格線 ················.177 15.1.5 設(shè)置圖例 ···················.178 15.1.6 設(shè)置圖表標(biāo)題 ·············.179 15.1.7 設(shè)置數(shù)據(jù)標(biāo)簽 ·············.180 15.1.8 設(shè)置數(shù)據(jù)表 ················.181 15.1.9 繪制常用幾何圖形 ·······.182 15.2 常用圖表的創(chuàng)建 ····················.186 15.2.1 折線圖 ······················.186 15.2.2 柱形圖 ······················.188 15.2.3 餅圖和圓環(huán)圖 ·············.191 15.2.4 散點(diǎn)圖和氣泡圖 ··········.191 15.2.5 直方圖 ······················.193 15.2.6 箱形圖 ······················.194 15.2.7 等高線圖 ···················.196 15.2.8 階梯圖 ······················.196 第16 章 使用seaborn 可視化數(shù)據(jù) ·····························198 16.1 seaborn 的樣式 ······················.198 16.1.1 基本樣式 ···················.198 16.1.2 自定義樣式 ················.199 16.2 繪制分布圖 ··························.200 16.2.1 單變量分布圖 ·············.200 16.2.2 多變量分布圖 ·············.202 16.3 繪制分類圖 ··························.204 16.3.1 分類散點(diǎn)圖 ················.204 16.3.2 箱形圖與琴形圖 ··········.204 16.3.3 回歸圖 ······················.205 第17 章 使用pyecharts 動(dòng)態(tài)可視化數(shù)據(jù) ····················207 17.1 pyecharts 的版本與特點(diǎn) ···········.207 17.2 pyechats 可視化的流程及選項(xiàng)設(shè)置 ···································.207 17.2.1 pyecharts 可視化的一般流程 ·························.207 17.2.2 pyecharts 選項(xiàng)設(shè)置 ·······.209 17.2.3 pyecharts 常用的圖表設(shè)置方法 ·····················211 17.3 使用pyecharts 創(chuàng)建圖表 ··········.214 17.3.1 餅圖和圓環(huán)圖 ·············.214 17.3.2 折線圖和面積圖 ··········.216 17.3.3 散點(diǎn)圖和氣泡圖 ··········.218 17.3.4 直方圖和箱形圖 ··········.219 17.3.5 詞云圖 ······················.221 17.3.6 數(shù)據(jù)地圖 ···················.222 17.3.7 雷達(dá)圖 ······················.224 17.3.8 儀表盤和水球圖 ··········.225 第18 章 使用SciPy 進(jìn)行科學(xué)計(jì)算和統(tǒng)計(jì)分析 ··············227 18.1 使用SciPy 進(jìn)行科學(xué)計(jì)算 ·········.227 18.1.1 獲取基本科學(xué)常量 ·······.227 18.1.2 線性代數(shù)和微積分 ·······.228 18.1.3 插值與擬合 ················.229 18.2 使用SciPy 進(jìn)行統(tǒng)計(jì)分析 ·········.230 18.2.1 正態(tài)分布有關(guān)計(jì)算 ·······.230 18.2.2 通過樣本推斷總體參數(shù) ·························.231 18.2.3 檢驗(yàn)均值 ···················.232 18.2.4 檢驗(yàn)均值差 ················.233 18.2.5 卡方檢驗(yàn) ···················.234 18.2.6 回歸分析 ···················.235 第四篇 實(shí) 例 應(yīng) 用 第19 章 共享自行車大數(shù)據(jù)分析 ·····239 19.1 數(shù)據(jù)預(yù)處理 ··························.239 19.1.1 讀取數(shù)據(jù) ···················.239 19.1.2 數(shù)據(jù)清洗與轉(zhuǎn)換 ··········.240 19.2 探索數(shù)據(jù)規(guī)律 ·······················.241 19.2.1 年份數(shù)據(jù)比較 ·············.241 19.2.2 月份趨勢(shì)比較 ·············.241 19.2.3 每日高峰時(shí)段分析 ·······.243 19.2.4 不同季度差異分析 ·······.244 19.2.5 周末和工作日差異分析 ·························.245 第20 章 在線銷售數(shù)據(jù)分析與建模 ··246 20.1 獲取和清洗數(shù)據(jù) ····················.246 20.1.1 獲取數(shù)據(jù) ···················.246 20.1.2 了解數(shù)據(jù)的基本特征 ····.247 20.1.3 清洗與整理數(shù)據(jù) ··········.248 20.2 分析與可視化銷售數(shù)據(jù) ···········.249 20.2.1 查看銷量的描述統(tǒng)計(jì)結(jié)果 ·························.249 20.2.2 按產(chǎn)品對(duì)銷量進(jìn)行匯總 ·························.249 20.2.3 按城市匯總產(chǎn)品 ··········.250 20.2.4 對(duì)產(chǎn)品和城市進(jìn)行交叉分析 ·························.251 20.3 銷量趨勢(shì)分析 ·······················.251 20.3.1 日期格式轉(zhuǎn)換 ·············.252 20.3.2 時(shí)間和季節(jié)趨勢(shì)分析 ····.252 20.3.3 比較不同城市季節(jié)趨勢(shì)的差異 ·························.253
你還可能感興趣
我要評(píng)論
|