0

I have been trying to update all rows value of a specific column where another column's value matches with a specific value.I have followed this link:Modifying a subset of rows in a pandas dataframe

Using this just changes the very last row value,but all the other row values remain unchanged. Here is my code:

def update_status(self, isbn=0, status='yes'):
    print("\nUpdating Status\n")
    df = self.data
    ndf = df[df['ISBN']==isbn]
    if len(ndf) > 0:
        print(df)
        df.loc[df.ISBN==(isbn), 'STATUS'] = status
        print(df)
        print("\nUpdated\n")
        self.data=df[['ID', 'AUTHOR', 'ISBN', 'TITLE', 'YEAR', 'STATUS']].copy()
        os.remove(self.filname)
        self.data.to_csv(self.filname, sep=',', encoding='utf-8')
    else:
        print("No Book Found\n")

Here is the output where ISBN=9332549532 and status='yes' output

instead of changing 2 rows ,only the last row is getting changed
It will be really helpful if i get the solution.
Thanks

  • Have you made sure that the ISBN column doesn't have hidden characters that could make the value in the row with the same ISBN number not match? Without having a sample of the data to test things it's hard to be able to help. – Oriol Mirosa Apr 06 '18 at 00:57
  • Welcome to SO! Please provide a minimal example (few rows) of the input data and the expected output (not as an image). Read more here: http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – YOLO Apr 06 '18 at 01:11

0 Answers0