Based on the error message I guess predsLilas1.csv is not created, while you are trying to append to the file. You could try to pass a+ as the mode, which should create the file, if it doesn’t exist or make sure that the file is in the right folder via os.path.exists('predsLilas1.csv').