Brian的雜記
  • Introduction
  • Brian's 雜記
    • My Awesome API
    • FB 大頭貼
    • 硬體雜記
    • PHP
    • project
      • 模擬器
      • WAMP
    • WinMerge
    • 雜記
      • LINQ
      • 方法
      • Grid View
      • namespace
      • global
      • 物件導向
      • Excel
      • VS2017
      • single sign on
      • Master
      • Https
      • 憑證
      • 略過憑證不符
      • NLog
      • 團隊開發
      • .NET Core
      • 共用網路上的芳鄰
      • 爬蟲
      • NPOI
      • RSS
      • 多執行緒
      • 記憶體回收
      • 密碼學
        • BCrypt
        • AES
      • 主機環境建置
      • Session
      • Error
      • IIS 相關
      • 無障礙相關
      • 介面
        • 影像地圖
      • telnet
        • smtp
      • nslookup
      • 協助客戶解決問題
      • 驗證欄位
      • 網站管理
      • 工具整理
    • 正規表示法
    • 影像處理
    • IntelliJ Idea
    • 觀念
      • Clean Code
        • 命名
        • 函式
        • 註解
        • 編排
        • 物件及資料結構
        • 錯誤處理
        • 邊界
        • 單元測試
        • 類別
      • Java 程式風格
      • Design Pattern
        • 單例模式
      • 同步
      • 畫圖
        • ER-Model
        • 類別圖
        • Use Case
        • 有限狀態機
      • 資料 API 文件 分析
      • CORS & SSL
      • 利用DISC幫助溝通
      • OAS
    • 檔案上傳
      • FileStore
      • App Engine
      • Google Storage
    • OAuth vs Open ID
    • MIME
    • 虛擬桌面
    • 待看資料
    • Selenium
    • CDN
    • HTTP
    • 編碼
    • 2nd-ML100Days
      • jupyter
    • 微服務
      • 設計
        • 1 ~ 5
        • 6
        • 7
        • 8
        • 9
    • Gradle
    • Maven
    • Error
    • 批次檔 BAT
    • Kurento
    • WebSocket & WebRTC
  • 需求面能力
    • User Story
  • Google Cloud Platform
    • Compute Engine
  • Python
    • 基本語法
    • Pandas
    • 套件
    • Matplotlib
    • Encoder
    • jupyter
  • Java
    • Java
      • File
      • Exception
      • 物件導向觀念
      • 加密
      • HTTP
      • 集合
      • Stream()
      • Web
      • ResultSet
      • JDK6
      • JDK8
    • 讀取、複寫MP3 Tag
    • Log4j2
    • Servlet
      • 容器
    • JSP
    • JBOSS
    • JWT
    • PreparedStatement
    • Error
    • Spring
      • Spring Boot
        • @Value
        • Build
      • RequestParameter
      • Error
      • Autowired
      • JPA
      • FeignClient
      • WebSocket
      • thymeleaf
      • Security
      • Test
      • Scheduled
      • Redirect
    • IntelliJ
  • Linux
    • Linux
    • Shell Script
    • Cygwin(在Windows執行Linux指令)
  • 前端
    • HTML
      • Link
    • CSS
      • Position
      • padding color
      • display
    • JS
      • jQuery
        • Select2
      • fancybox
      • ES6
      • 效能
      • GoogleMap API
        • Marker
        • InfoWindow
      • 事件
      • CKEditor
      • TGOS
      • JSON
      • QRcode
      • 核心概念
        • 物件 變數 型別
          • number
          • String
          • boolean
          • null & undefined
          • Symbol
        • JS 物件概念
        • 深入理解JS 函式物件
        • 更多ES2015/ES6 全新語言特性
      • Promise
    • 效果應用
  • 資料庫
    • 注意事項
    • MariaDB
    • MySQL
      • inner join 和 join
      • 字串比對
      • 倒數資料
    • SQL
      • DDL 資料定義語言
      • DML 資料操縱語言
      • DCL 資料控制語言
      • TCL 交易控制語言
      • T-SQL
      • CTE
      • JOIN
    • Oracle
    • MSSQL 操作
      • 新增使用者
      • SQL 指令
      • Sequence
    • 差異比較
    • MyBatis
    • Workbench 操作
    • SQL Injection
  • 版本控制
    • Gitlab
      • sign up
      • sign in
      • add project
      • add members
    • SourceGit
      • install
    • SmartGit
      • install
      • operate
      • git 操作雜記
    • TortoiseGit
    • Git
    • TFS
    • SVN
  • Test
    • 軟體測試原則
    • 演算法
    • XMind
      • install
    • Jenkins
      • 建置
    • HTTPie
    • Postman
    • 測試驅動開發
    • 撰寫測試的觀念
    • 測試框架
    • IoC & DI
    • 隔絕相依性的方式
    • JUnit
    • NUnit
    • 習慣
    • 虛設常式
  • Angular
    • hello world
    • ng-options
    • ES6
    • Build & Conponect
    • HttpClient
    • 部署
  • ASP.NET Web Form
    • Chapter 2
      • 2-1
        • 小東西
    • 略過請求驗證
  • Go
Powered by GitBook
On this page
  • 資料結構
  • Series
  • DataFrame
  • Panel
  • 讀取檔案
  • CSV
  • Html
  • 方法
  • 排序
  • 判斷是否為空
  • 檢查特定值
  • 處理空值
  • 檢查重複值
  • 檢查區間值
  • 修改值
  • 修改 columnName
  • 用 replace() 重新編碼
  • 畫圖
  • 折線圖
  • DataFrame 的操作
  • .shape
  • .describe()
  • .head()
  • .tail()
  • .columns
  • .index
  • info()

Was this helpful?

  1. Python

Pandas

Previous基本語法Next套件

Last updated 5 years ago

Was this helpful?

參考資料:() 參考資料:()

Python 的一種數據分析 lib 提供主要兩種資料結構 DataFrame & Series 透過載入至資料結構物件後,可以使用物件提供的方法,來快速進行前處理(資料補值、空值去除、取代) 更多的輸入、輸出整合,EX:從DB讀取資料,將處理完的資料倒回DB

資料結構

Series

用來處理時間序列相關的資料 (如感測器資料) 主要為建立索引的一維陣列

DataFrame

則是用來處理結構化 (Table like) 的資料 有 列索引 與 欄標籤 的二維資料 例如:關聯式資料庫、CSV

Panel

用來處理有資料、索引、列索引、欄標籤 的三維資料集。

讀取檔案

CSV

import pandas as pd #引用套件並縮寫為 pd
df = pd.read_csv('fileName.csv')
print(df)

Html

import pandas as pd
dfs = pd.read_html('url')
dfs[0]

方法

排序

.sort_index() .sort_values()

判斷是否為空

isnull() notnull() isna()

檢查特定值

isin(value)

處理空值

dropna() #有 null 都刪除

fillna(0) #有null 都補0 fillna({'key': "NULL", "key2": 0}) #依照欄位補值

檢查重複值

df.duplicated('columnName')

檢查區間值

.between(value1,value2)

修改值

df.loc[index, column] = value

修改 columnName

df.rename(columns = {column : cloumn_modify})

用 replace() 重新編碼

1 和 2 改為 1,3 和 4 改為 2 df[column].replace({1:1, 2:1, 3:2, 4:2}, inplace=True) #inplace=True 才會寫入

畫圖

折線圖

s = Series(np.random.randn(10).cumsum(), index = np.arange(0, 100, 10))
s.plot()

DataFrame 的操作

.shape

return 列數、欄數

.describe()

return 描述性統計

count 筆數 mean 平均數 std 標準差 min 最小值 25% 各四分位數 50% 75% max 最大值

.head()

return 前五筆 (可代入 n,則回傳 n 筆)

.tail()

return 後五筆 (同上)

.columns

return 欄位名稱

.index

return index

info()

return 資料內容

參考資料:()

https://oranwind.org/python-pandas-ji-chu-jiao-xue/
https://srdatw.blogspot.com/2019/01/python-pandas.html
https://amaozhao.gitbooks.io/pandas-notebook/content/pandas%E4%B8%AD%E7%9A%84%E7%BB%98%E5%9B%BE%E5%87%BD%E6%95%B0.html