PCA can be a powerful tool for spectral decomposition of variable X-ray data. It is particularly useful when multiple variable components contribute to the net spectrum and variance, as these components can then be isolated.
The code for used for this analysis can be found through the link below, although significant modification may be required depending on the use case.
Please bear in mind that I wrote this code while I was still a graduate student, and it is inefficient and poorly documented! The basic methodology is to construct a 2D array of normalised residual count rates as a function of time and energy, then pass that array through the numpy singular value decomposition function.