手动更改CSV文件上的数据导致数据显示为NaN

问题描述

所以我有一个从以下代码生成的CSV文件

import pandas as pd
df = pd.read_csv('input_file.csv',encoding="utf-16")
from googletrans import Translator
translator = Translator()
df['english'] = df['Comment'].apply(translator.translate,src='id',dest='en')
#print(df)
#print(df['english'])
from textblob import TextBlob
def sentiment_calc(text):
    try:
        return TextBlob(text).sentiment
    except:
        return None
df['english'] = df['english'].astype(str) #change type to string 
df['sentiment']=df['english'].apply(lambda text: TextBlob(text).sentiment)
#print(df['sentiment'])
df.to_csv('output_file.csv',mode='w',index=False,encoding="utf-16")

这是结果

Comment  ...                                          sentiment
0     seni bahasa pemerintah new normal protokol kes...  ...  Sentiment(polarity=0.1431818181818182,subject...
1     we need thanos to bring balance to the our uni...  ...          Sentiment(polarity=0.0,subjectivity=0.0)
2     terserah lah mau ngomong apa pusing denger dia...  ...          Sentiment(polarity=0.0,subjectivity=0.0)
3     mirip protokol di parkiran motor helm hilang r...  ...          Sentiment(polarity=0.6,subjectivity=1.0)
4     ga kebayang kita hidup dijaman yg serba salah ...  ...  Sentiment(polarity=0.3181818181818182,subject...
                                                ...  ...                                                ...
4966  klu pake sarungtangan ke mall megang ini itu m...  ...      Sentiment(polarity=0.25,subjectivity=0.3125)
4967  bukannya ini orang yg bikin mesjid dg konsep i...  ...  Sentiment(polarity=0.0,subjectivity=0.0666666...
4968  ribet bnget cuma di tahap implementasi akan su...  ...  Sentiment(polarity=-0.3333333333333333,subjec...
4969  mal dibuka bahasa adaptasi tau g sih covid ini...  ...  Sentiment(polarity=0.21250000000000002,subjec...
4970  kenapa kita pilih new normal kalau ternyata ad...  ...  Sentiment(polarity=0.053856749311294756,subje...

[4971 rows x 3 columns]

但是随后我需要在情感列上手动更改一些数字。更改这些数字后,当我再次使用df = pd.read_csv('output_file.csv',encoding="utf_16")读取CSV继续进行分析时。整个列变为NaN。

Comment  english  sentiment
0     seni bahasa pemerintah new normal protokol kes...      NaN        NaN
1     we need thanos to bring balance to the our uni...      NaN        NaN
2     terserah lah mau ngomong apa pusing denger dia...      NaN        NaN
3     mirip protokol di parkiran motor helm hilang r...      NaN        NaN
4     ga kebayang kita hidup dijaman yg serba salah ...      NaN        NaN
                                                ...      ...        ...
4966  klu pake sarungtangan ke mall megang ini itu m...      NaN        NaN
4967  bukannya ini orang yg bikin mesjid dg konsep i...      NaN        NaN
4968  ribet bnget cuma di tahap implementasi akan su...      NaN        NaN
4969  mal dibuka bahasa adaptasi tau g sih covid ini...      NaN        NaN
4970  kenapa kita pilih new normal kalau ternyata ad...      NaN        NaN

[4971 rows x 3 columns]

有什么方法可以使我的情感专栏不成为NaN吗?

the csv file

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...