It is unfortunate that we do not get the opportunity to see what ‘X’ is for the various files, nor anything else about them.
If you always (and only) want to remove the last column, then:
would work, and you can completely remove this line:
that may be throwing the error.
might be appropriate.
We have no way of testing that to determine what may be best.