pandas第一課函數
首先是數據的準備spa
movies.datcode
user.datblog
ratings.datip
注意,這些數據都是經過::來隔開每一列的,每一列有各自的含義utf-8
如今經過pandas來讀入數據pandas
首先是定義一個列表,列出每一列的名稱it
而後就用pd.read_table()函數來讀入整個數據文件。io
程序以下:table
# -*- coding: utf-8 -*- """ Created on Wed Sep 5 11:09:33 2018 @author: user """ import pandas as pd unames = ['user_id', 'gender', 'age','occupation','zip'] users = pd.read_table('users.dat', sep='::',header=None, names=unames) rnames = ['user_id', 'movie_id', 'rating', 'timestamp'] ratings = pd.read_table('ratings.dat', sep='::', header=None, names=rnames) mnames = ['movie_id', 'title', 'genres'] movies = pd.read_table('movies.dat', sep='::', header=None, names=mnames)
讀入數據後,生成的結果爲: