我有一个由两列组成的具有多对多关系的表。你知道吗
例如
Animal Food
rabbit grass
rabbit carrots
rabbit cabbage
dog carrots
horse grass
horse hay
我想要这样的东西:
Animal Food1 Food2 Food3
rabbit grass carrots cabbage
dog carrots
horse grass hay
或者类似的:
Animal Grass Carrots Cabbage Hay
rabbit True True True False
dog False True False False
horse True False False True
我试过pivot table、melt和stack,但仍然不知道如何做到这一点。任何帮助都将不胜感激。谢谢!!你知道吗
输出:
选项1
groupby
与size
选项2
groupby
与value_counts
选项3
groupby
和str.get_dummies
选项4
pandas.factorize
与numpy.bincount
选项5
我很无聊。。。所以想出了更多的
您可以使用:
或:
相关问题 更多 >
编程相关推荐