其他文件类型简介

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 数据导入入门

Passons à la pratique !

Python 数据导入入门

Preparing Video For Download...