如何在数据框单元格中插入列表

2024-09-29 03:39:18 发布

您现在位置:Python中文网/ 问答频道 /正文

如何将项目列表插入数据框的单元格中?在这段代码中,clean_text函数返回一个列表,然后我想将该列表保存在“abstract_processed”和“body_processed”列的特定行中

for i,content in dfp["abstract"].iteritems():
  if type(content) == type("this is a string"):
    dfp.loc[i,'abstract_processed']=clean_text(content,word_tokenize,stopwords)
  else:
    dfp.loc[i,'abstract_processed']="lacking"


for i,content in dfp["body_text"].iteritems():
  if type(content) == type("this is a string"):
    dfp.loc[i,'body_processed']=clean_text(content,word_tokenize,stopwords)
  else:
    dfp.loc[i,'body_processed']="lacking"

dfp.head()

Tags: textincleanabstract列表foriftype