Transition metal-nitrogen-doped carbons (TMNCs) are a promising class of catalysts for the CO2 electrochemical reduction reaction. In particular, high CO2-to-CO conversion activities and selectivities were demonstrated for Ni-based TMNCs. Nonetheless, open questions remain about the nature, stability, and evolution of the Ni active sites during the reaction. In this work, we address this issue by combining operando X-ray absorption spectroscopy with advanced data analysis. In particular, we show that the combination of unsupervised and supervised machine learning approaches is able to decipher the X-ray absorption near edge structure (XANES) of the TMNCs, disentangling the contributions of different metal sites coexisting in the working TMNC catalyst. Moreover, quantitative structural information about the local environment of active species, including their interaction with adsorbates, has been obtained, shedding light on the complex dynamic mechanism of the CO2 electroreduction.