使用 Pandas 从 CSV 文件中提取值

约翰·多伊

我有一个 CSV 文件,其中数据被组织成两列。

在此处输入图片说明

如何将负面情绪和正面情绪保存在单独的 csv 文件中。我的代码如下:

import pandas as pd 

df = pd.read_csv('~/Downloads/epinions3.csv')

df_neg = df.loc[['Neg']] # get all negative sentiments and then save to a file 

df_pos = # get all positive sentiments and save to a file 

print(df_neg)
可可18
df.loc[df['class'] == 'Neg'].to_csv('negative.csv', index=False)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章