其他檔案類型導論

Python 資料匯入入門

Hugo Bowne-Anderson

Data Scientist at DataCamp

其他檔案類型

  • Excel 試算表
  • MATLAB 檔
  • SAS 檔
  • Stata 檔
  • HDF5 檔
Python 資料匯入入門

Pickle 檔

  • Python 原生檔案類型
  • 動機:有許多不易儲存的資料型別
  • Pickle 檔會序列化
  • 序列化=將物件轉為位元串流
Python 資料匯入入門

Pickle 檔

import pickle
with open('pickled_fruit.pkl', 'rb') as file:
    data = pickle.load(file)    
print(data)
{'peaches': 13, 'apples': 4, 'oranges': 11}
Python 資料匯入入門

匯入 Excel 試算表

import pandas as pd
file = 'urbanpop.xlsx'
data = pd.ExcelFile(file)
print(data.sheet_names)
['1960-1966', '1967-1974', '1975-2011']
df1 = data.parse('1960-1966') # sheet name, as a string
df2 = data.parse(0) # sheet index, as a float
Python 資料匯入入門

你將學到:

  • 自訂匯入方式
  • 略過列
  • 匯入特定欄
  • 更改欄名
Python 資料匯入入門

一起來練習吧!

Python 資料匯入入門

Preparing Video For Download...