import pyfits for framenum in range(7146,7165): file_name = 'lm_190224_'+str("{0:0>6d}".format(framenum))+'.fits' # read in the file sciImg, header = pyfits.getdata(file_name,0,header=True) # change the PID number header["PID"] = 69 # if the readout is a 16-bit signed integer, keep it that way sciImg = sciImg.astype(np.int16) hdu = pyfits.PrimaryHDU(sciImg, header=header) hdul = pyfits.HDUList([hdu]) # write new file to a different directory to avoid mistakes hdul.writeto("escrow/" + file_name, clobber=False) print('Saved ' + file_name)