gpt4 book ai didi

python - 将列表元组 (index, list(features)) 转换为具有列值作为特征 bool 值的 DataFrame

转载 作者:太空宇宙 更新时间:2023-11-03 14:05:30 24 4
gpt4 key购买 nike

我有以下数据列表:

[(1, [1,2]), (2, [1,2]), (3,[1])]

并想将其转换为 pandas 数据框

   1   2  
1 True True
2 True True
3 True False

有内置方法吗?

最佳答案

index, data = zip(*[(1, [1,2]), (2, [1,2]), (3,[1])])
pd.DataFrame(list(data), index, [1, 2]).notnull()

1 2
1 True True
2 True True
3 True False

关于python - 将列表元组 (index, list(features)) 转换为具有列值作为特征 bool 值的 DataFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43901717/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com