how do i import from a unicode (utf-8) csv file into a numpy array

前端 未结 1 2031
走了就别回头了
走了就别回头了 2021-01-15 09:45

im not trying to do this smart or fast, just trying to do it at all.

i have a file looks like this :

$ cat all_user_token_counts.csv  
@5raphaels,in,         


        
相关标签:
1条回答
  • 2021-01-15 10:36

    This can be done easily with np.loadtxt:

    import numpy as np
    arr=np.loadtxt('all_user_token_counts.csv',delimiter=',',
                      dtype = '|U10,<U10,int')
    print(arr)
    
    # [(u'@5raphaels', u'in', 15) (u'@5raphaels', u'for', 15)
    #  (u'@5raphaels', u'unless', 11) (u'@5raphaels', u'you', 11)]
    
    0 讨论(0)
提交回复
热议问题