如何添加目标列中的字符串计数。你知道吗
data = [{'target': ['Aging','Brain', 'Neurons', 'Genetics']},
{'target': ['Dementia', 'Genetics']},
{'target': ['Brain','Dementia', 'Genetics']}]
df = pd.DataFrame(data)
数据帧
target
0 [Aging, Brain, Neurons, Genetics]
1 [Dementia, Genetics]
2 [Brain, Dementia, Genetics]
唯一标签
target = []
for sublist in df['target'].values:
tmp_list = [x.strip() for x in sublist]
target.extend(tmp_list)
target = list(set(target))
# ['Brain', 'Neurons', 'Aging', 'Genetics', 'Dementia']
也许这会有帮助
如果需要指示符列(仅
0
或1
):使用^{} :
或者^{} 和^{} -但是它更慢:
如果需要列表中的计数值:
相关问题 更多 >
编程相关推荐