แนะนำไฟล์ประเภทอื่น

Python เบื้องต้น: การนำเข้าข้อมูล

Hugo Bowne-Anderson

Data Scientist at DataCamp

ไฟล์ประเภทอื่น

  • Excel spreadsheets
  • ไฟล์ MATLAB
  • ไฟล์ SAS
  • ไฟล์ Stata
  • ไฟล์ HDF5
Python เบื้องต้น: การนำเข้าข้อมูล

Pickled files

  • ไฟล์ประเภทที่เป็นเนทีฟของ Python
  • ข้อมูลหลายชนิดไม่มีวิธีจัดเก็บที่ชัดเจน
  • ไฟล์ Pickle คือไฟล์ที่ผ่านการ serialize
  • Serialize = แปลงอ็อบเจกต์เป็น bytestream
Python เบื้องต้น: การนำเข้าข้อมูล

Pickled files

import pickle
with open('pickled_fruit.pkl', 'rb') as file:
    data = pickle.load(file)    
print(data)
{'peaches': 13, 'apples': 4, 'oranges': 11}
Python เบื้องต้น: การนำเข้าข้อมูล

การนำเข้า Excel spreadsheets

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...