python-加载数据集

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

【问题1】路径问题

使用data_filename=os.path.join(os.path.expanduser("~")+"\PycharmProjects\\BiyeE","data","A.csv") 其中结合os.path.expanduser("~")得到主路径位置,本机是C:\User\Adminstrator,

路径中使用\进行转义

【问题2】大文件数据读取报“Memory Error”-待解决

import csv
def loadData():
    f=open("../data/tc_train_user.csv")
    rows=csv.reader(f)
    rows.next()
    for row in rows:
                           做操作

你可能感兴趣的:(Python)