Search code examples
pandasdataframekeyerrorcorpus

For loop KeyError: 4675 when making corpus from Pandas dataframe


I've tried to make corpus from Pandas dataframe (with shape (14454, 9)). However, whenever the range exceeds 10k, the for loop return KeyError: 4675 , yet works well for 10k below.

# getting the entire text
# this works fine
corpus=" "

for i in range(0,998):
    corpus= corpus+ ' ' + df["Cleaned_text"][i]
# this return Keyerror:4675  
corpus=" "

for i in range(0,14453):
    corpus= corpus+ ' ' + df["Cleaned_text"][i]

any ideas there clear this with thanks :)


Solution

  • Just need to use iloc function

    #getting the entire resume text
    
    corpus=" "
    
    for i in range(0,14454):
        corpus= corpus+ ' ' + df["Cleaned_Resume"].iloc[i]
    

    sr for my newbie but still keep as someone might need it