【发布时间】:2020-10-06 00:54:42
【问题描述】:
这里是初学者。我想在我的数据帧上使用一种热编码,该数据帧在一列中有多个分类数据。我的数据框看起来像这样,尽管列中有更多内容,因此我无法手动完成:
Title column
Movie 1 Action, Fantasy
Movie 2 Fantasy, Drama
Movie 3 Action
Movie 4 Sci-Fi, Romance, Comedy
Movie 5 NA
etc.
我想要的输出:
Title Action Fantasy Drama Sci-Fi Romance Comedy
Movie 1 1 1 0 0 0 0
Movie 2 0 1 1 0 0 0
Movie 3 1 0 0 0 0 0
Movie 4 0 0 0 1 1 1
Movie 5 0 0 0 0 0 0
etc.
谢谢!
【问题讨论】:
-
你是否提前知道列中所有可能的值(即A、B、...F)?
-
欢迎来到 Stackoverflow!请使用所需的行为、特定问题和重现问题的代码更新您的问题。请参阅:如何创建a Minimal, Complete, and Verifiable example。
-
@AlenaVolkova 是的,我知道列中的可能值。
-
@HeisAif 我不确定该放什么,因为到目前为止我唯一拥有的是来自 .csv 文件的数据框。我现在的问题是如何在我的数据帧上使用一种热编码。