嗨,我有一个数据帧,如下所示:
并希望创建包含2列的数据帧:
写入器1写入器2
上面列出了一首歌的所有编剧:在《03邦妮与克莱德》中,作者包括:普林斯、图帕克·沙库尔、杰伊·兹、泰龙·赖斯和坎耶·韦斯特。因此,我的数据帧应该如下所示:
Writer1 Writer2
Prince Tupac Shakur
Prince Jay-Z
Prince Tyrone Wrice
Prince Kanye West
Tupac S Jay-Z
Tupac S Tyrone Wrice
Tupac S Kanye West
Jay-Z Tyrone Wrice
Jay-Z Kanye West
Tyrone Kanye West
你知道我该怎么做吗?在
下面是一种使用
itertools.combinations
的方法:请注意,这假设您的数据是Pandas数据帧的形式。您可以轻松地从文本文件或csv中读入,或创建一个类似于以下内容的文件进行测试:
^{pr2}$如果您想在整个数据帧上有效地应用此功能,请考虑:
这将返回一个数据帧,其中以歌曲为索引,所需的列给出了每首歌曲的所有编剧组合。在
相关问题 更多 >
编程相关推荐