Data loading using arrays in Python

前端 未结 3 1356
感情败类
感情败类 2021-01-21 20:17

Have a data in such format in .txt file:

UserId   WordID
  1       20
  1       30
  1       40
  2       25
  2       16
  3       56
  3       44
  3       12
         


        
3条回答
  •  走了就别回头了
    2021-01-21 20:37

    while you might be more interested in doing it in pandas depending on your purpose, the numpy way would be:

    userid,wordid = np.loadtxt('/data/file.txt',skiprows=1,unpack=True)
    #example use:
    mylist = []
    for uid in np.unique(userid):
        mylist.append(wordid[userid==uid])
    

提交回复
热议问题