我创建了这些列表来存储我在for循环上生成的东西,该循环显示得更靠下一点
neutralScore = []
lightPosScore = []
middlePosScore = []
heavyPosScore = []
lightNegScore = []
middleNegScore = []
heavyNegScore = []
循环来了
score = float
convertStringToInt = get_sent_score_comp_df.apply(lambda x: float(x))
for score in convertStringToInt:
if score <= 0.09 and score >= -0.09:
neutralScore.append(score)
elif score >= 0.091 and score <= 0.49:
lightPosScore.append(score)
我想将我的情绪保存到这些列表中,然后加入它们,以便能够将它们转换为数据帧,并将它们存储在MySQl数据库中。 有没有一种优雅的方法可以做到这一点
scores = pandas.DataFrame(data=neutralScore).append(lightPosScore, middlePosScore, heavyPosScore).append(
lightNegScore,
middleNegScore,
heavyNegScore).columns = ['heavyPosScore', 'middlePosScore', 'lightPosScore', 'neutralScore', 'lightNegScore', 'middleNegScore', 'heavyNegScore']
我知道,声明列列表需要单独完成,但到目前为止,代码看起来是这样的
到目前为止,我尝试了这个,但它没有工作,因为它返回:
Can only merge Series or DataFrame objects, a <class 'list'> was passed
这是可以理解的,但我现在想不出解决问题的办法
问题并不完全清楚您希望最终的数据帧是什么样子。但我会这样做:
和
'heavyPosScore', 'middlePosScore', 'lightNegScore', 'middleNegScore', 'heavyNegScore'
列类似然后,您可以像这样轻松地筛选分数类型:
编辑
要有一个
rating
列,首先定义一个函数来给出您的评级,并将其应用于score
列:相关问题 更多 >
编程相关推荐