import numpy as np import os import pandas as pd import csv
def loadData(): data_filename=os.path.join(os.path.expanduser("~")+"\PycharmProjects\\biye","data","tianchi_mobile_recommend_train_user.csv") colname=["user_id","item_id","behavior_type","user_geohash","item_category","time"] traindata=pd.read_csv(data_filename,header=1,names=colname,sep=',') return traindata
使用data_filename=os.path.join(os.path.expanduser("~")+"\PycharmProjects\\BiyeE","data","A.csv") 其中结合os.path.expanduser("~")得到主路径位置,本机是C:\User\Adminstrator,
路径中使用\进行转义
import csv def loadData(): f=open("../data/tc_train_user.csv") rows=csv.reader(f) rows.next() for row in rows:做操作