我的get
数据框中的labels
列如下:
test['labels']
对于列(0 ['Edit Distance']
1 ['Island Perimeter']
2 ['Longest Substring with At Most K Distinct Ch...
3 ['Valid Parentheses']
4 ['Intersection of Two Arrays II']
5 ['N-Queens']
)的字符串表示形式的列中的每个值,我想应用下面的函数将其转换为实际列表。
"['Edit Distance']"
执行此操作的直接方法是什么?
答案 0 :(得分:4)
使用:
import ast
test['labels'] = test['labels'].apply(ast.literal_eval)
print (test)
labels
0 [Edit Distance]
1 [Island Perimeter]
2 [Longest Substring with At Most K Distinct Ch]
3 [Valid Parentheses]
4 [Intersection of Two Arrays II]
5 [N-Queens]