Python Forum
KeyError -read multiple lines
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
KeyError -read multiple lines
#3
Thank you. I have updated the code to

for i in range(0, 1000):  
     
        
    # column : "Review", row ith
    try:
        review = re.sub('[^a-zA-Z]', ' ', dataset['Review'][i])  
      
        # convert all cases to lower cases 
        review = review.lower()  
      
        # split to array(default delimiter is " ") 
        review = review.split()  
      
        # creating PorterStemmer object to 
        # take main stem of each word 
        ps = PorterStemmer()  
      
        # loop for stemming each word 
        # in string array at ith row     
        review = [ps.stem(word) for word in review 
                if not word in set(stopwords.words('english'))]  
                  
        # rejoin all string array elements 
        # to create back into a string 
        review = ' '.join(review)   
      
        # append each string to create 
        # array of clean text  
        corpus.append(review)
    except KeyError as e:
        print(ps.stem(review))
I seem to get the numerous lines of the same review. I will lookf at the source file again and give feedback. The output is;

wife visit johannesburg famili function stay locat citi never felt comfort secur stay african pride melros arch mani restaur importantli servic attent staff african pride provid except cannot rave enough stay accommod would use citi world class
wife visit johannesburg famili function stay locat citi never felt comfort secur stay african pride melros arch mani restaur importantli servic attent staff african pride provid except cannot rave enough stay accommod would use citi world class
Reply


Messages In This Thread
KeyError -read multiple lines - by bongielondy - Nov-04-2019, 09:19 PM
RE: KeyError -read multiple lines - by MckJohan - Nov-04-2019, 11:37 PM
RE: KeyError -read multiple lines - by bongielondy - Nov-06-2019, 01:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to write the condition for deleting multiple lines? Lky 3 1,281 Jul-10-2022, 02:28 PM
Last Post: Lky
  Delete multiple lines from txt file Lky 6 2,529 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  Display table field on multiple lines, 'wordwrap' 3python 0 1,872 Aug-06-2021, 08:17 PM
Last Post: 3python
  Open and read multiple text files and match words kozaizsvemira 3 6,942 Jul-07-2021, 11:27 AM
Last Post: Larz60+
  [Solved] Trying to read specific lines from a file Laplace12 7 3,784 Jun-21-2021, 11:15 AM
Last Post: Laplace12
  pulling multiple lines from a txt IceJJFish69 3 2,716 Apr-26-2021, 05:56 PM
Last Post: snippsat
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 6,339 Aug-10-2020, 11:01 PM
Last Post: medatib531
  Python: Automated Script to Read Multiple Files in Respective Matrices Robotguy 7 4,456 Jul-03-2020, 01:34 AM
Last Post: bowlofred
  Read CSV error: python KeyError: 'Time' charlicruz 1 5,355 Jun-27-2020, 09:56 AM
Last Post: charlicruz
  Read Multiples Text Files get specific lines based criteria zinho 5 3,311 May-19-2020, 12:30 PM
Last Post: zinho

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020