You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已转换DataFrame列为字符串,调用GPT2_model仍报[E1041]错误

解决GPT2模型传入Pandas Series触发的ValueError问题

问题原因

你触发的ValueError和findings列的字符串类型转换无关,核心问题是GPT2_model不支持直接接收Pandas Series作为输入——它要求输入是单个字符串、Doc或bytes类型,但你直接传入了整列数据(Series对象)。

解决方案

使用Pandas的apply()方法遍历findings列的每一个元素,单独传入模型处理:

import pandas
df['findings'] = df['findings'].astype(str)
# 逐行调用模型生成结果
df["new_column"] = df['findings'].apply(lambda x: GPT2_model(x, min_length=60))

优化说明

如果你的数据集较大,apply()的速度可能偏慢,可以借助swifter库实现自动优化(无需修改逻辑,仅替换调用方式):

# 先安装swifter:pip install swifter
import swifter
df["new_column"] = df['findings'].swifter.apply(lambda x: GPT2_model(x, min_length=60))

内容的提问来源于stack exchange,提问作者Jacob

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 02:20:48