如何在循环的每次迭代中向python中的数据帧插入标记化值和列的列表

2024-04-27 00:02:17 发布

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

for i in range(len(df1)):
    output=[]
    data= str(df1.iloc[i].NOTE)
    data1=data.lower()
    data1 = word_tokenize(data1)
    for words in data1:
        if words not in stop_words:
            output.append(words)
        if any(words.isdigit() for words in output):
            output.remove(words)
    print(df1.iloc[i].AMRI_PRESCRIPTION_ID,df1.iloc[i].AMRI_CLINICAL_NOTE_Q_ID,output)

这里outputtokenized值的列表。 上面的打印内容给出了结果:

127 1 ['second', 'episode', 'fever', 'last', 'week']

我需要将该值保存在数据帧中,然后将同一数据帧保存到数据库中的表中。请帮忙


Tags: 数据inidforoutputdatalenif