如何根据标签值分离数据框?
How to Separate Dataframe Based on the Label value?
假设我有这个数据框。
+-----------------+-----------+
| COMMENT | SENTIMENT |
+-----------------+-----------+
| Good app | Positive |
| Bad app | Negative |
| Useless feature | Negative |
| I like this app | Positive |
+-----------------+-----------+
我想根据 SENTIMENT 列拆分它。像下面这样。
+-----------------+-----------+
| COMMENT | SENTIMENT |
+-----------------+-----------+
| Good app | Positive |
| I like this app | Positive |
+-----------------+-----------+
+-----------------+-----------+
| COMMENT | SENTIMENT |
+-----------------+-----------+
| Bad app | Negative |
| Useless feature | Negative |
+-----------------+-----------+
有人知道 Python (Jupyter) 中针对这种情况的解决方案吗?你的帮助将有助于我的论文项目。谢谢 :D
你可以简单地使用df1 = df[df["SENTIMENT"]=="Positive"]
那么df1
将有:
df2 = df[df["SENTIMENT"]=="Negative"]
那么df2
将有:
假设我有这个数据框。
+-----------------+-----------+
| COMMENT | SENTIMENT |
+-----------------+-----------+
| Good app | Positive |
| Bad app | Negative |
| Useless feature | Negative |
| I like this app | Positive |
+-----------------+-----------+
我想根据 SENTIMENT 列拆分它。像下面这样。
+-----------------+-----------+
| COMMENT | SENTIMENT |
+-----------------+-----------+
| Good app | Positive |
| I like this app | Positive |
+-----------------+-----------+
+-----------------+-----------+
| COMMENT | SENTIMENT |
+-----------------+-----------+
| Bad app | Negative |
| Useless feature | Negative |
+-----------------+-----------+
有人知道 Python (Jupyter) 中针对这种情况的解决方案吗?你的帮助将有助于我的论文项目。谢谢 :D
你可以简单地使用df1 = df[df["SENTIMENT"]=="Positive"]
那么df1
将有:
df2 = df[df["SENTIMENT"]=="Negative"]
那么df2
将有: