2017-12-24 18 views
1
customer gender customer_ids 
    1   0  [1,2,3] 
    2   1  [6,2,1] 
    3   0  [4,3,9] 

위와 같이 CSV 파일에 일부 데이터가 있습니다. 나는이이 "['1','2','3']", ...팬더 : 목록으로 CSV 파일로드

같은 문자열로 CUSTOMER_IDS로드이

df = pd.read_csv('customer.csv', sep='\t') 

같은 csv 파일을로드하지만 데이터를로드하는 동안 나는이

[list([1,2,3]), list([6,2,1]), list([4,3,9])] 

답변

1

같은 NumPy와 배열로 CUSTOMER_IDS 데이터를 필요 converters 매개 변수를 지정하십시오. -

df = pd.read_csv('customer.csv', sep='\t', converters={'customer_ids' : pd.eval}) 
df 

    customer gender customer_ids 
0   1  0 [1, 2, 3] 
1   2  1 [6, 2, 1] 
2   3  0 [4, 3, 9] 

df.customer_ids.tolist() 
[[1, 2, 3], [6, 2, 1], [4, 3, 9]] 
+0

df.customer_ids 대신 .tolist(),이 작업은 df.customer_ids.values입니다. – user1670773