首页 > 解决方案 > AttributeError: 'int' 对象没有属性 'split' excel 错误

问题描述

我收到以下错误:

AttributeError: 'int' object has no attribute 'split'

我编写了一个代码来添加一个新列,并在给定的文本列中在特定单词之前提到 2 个单词,在之后提到两个单词。

我使用 nlp 在 python 中尝试了一个代码。

import openpyxl

path5 = "C:\\Users\\AC48330\\Desktop\\my files\\FINAL.xlsx"
wb = openpyxl.load_workbook(path5)
Sheet = wb['Sheet']
y = 'you'
line = Sheet['AW']

for i, cellObj in enumerate(Sheet['AW'], 1):
    for line in [i]:
        split_line = line.split()
    if y in split_line:
        index = split_line.index(y)
        print((' '.join(split_line[max(0, index - 2):min(index + 
                                 3,len(split_line))])), Sheet['BB'])
wb.save('finale.xlsx')

预期输出是 - 单词 word 关键字 word word - 在新列中

标签: pythonexcel

解决方案


推荐阅读