15th Discovery Challenge » Topic: Python – loading Data http://www.kde.cs.uni-kassel.de/ws/dc13/forums/topic/python-loading-data/feed/ Thu, 28 Aug 2014 10:22:32 +0000 http://bbpress.org/?v=2.2.4 en http://www.kde.cs.uni-kassel.de/ws/dc13/forums/topic/python-loading-data/#post-817 <![CDATA[Python – loading Data]]> http://www.kde.cs.uni-kassel.de/ws/dc13/forums/topic/python-loading-data/#post-817 Fri, 10 May 2013 18:18:28 +0000 thalesfc Since I have spent a lot of time debugging this, I`m sharing it.
If someone knows better way to do so, please speak:


from csv import reader

def loadNameList(path):
with open(path, 'r') as f:
data = []
for row in reader(f):
data.append(unicode(''.join(row), 'utf-8').lower().strip())
return data


def loadTestUsers(path):
with open(path, 'r') as f:
data = []
for line in f:
tokens = line.split('\t')
userID = int(tokens[0])
data.append(userID)
return data


def loadTrain(path):
with open(path) as f:
r = reader(f, delimiter='\t')
data = []
for userID, activity, name, _ in r:
# print userID, activity, name, timestamp
data.append([int(userID), activity, unicode(name, 'utf-8').lower().strip()])
return data

]]>