Answering the spatial relationship between ESG ratings and total factor productivity of enterprises can provide a reference for the high-quality development of macroeconomy and the sustainable and healthy development of enterprises. In this paper, the improved K-means algorithm-PCA-K-means is used to measure the principal component data corresponding to the economic development level of 26 central cities, based on which and cluster analysis is conducted to classify the regions and city types of East, Central and West China. Furthermore, benchmark regression and spatial heterogeneity analyses were conducted using a fixed-effects model. The study shows that ESG ratings have a significant positive relationship on firm-wide factors. Observing the PCA-K-means clustering results, it can be found that there is no significant positive effect between the economic development speed and the ESG ratings of enterprises, which indicates that there is a difference in the impact of ESG ratings on the total factor productivity of enterprises in different regions. Therefore, the spatial heterogeneity analysis shows that the correlation coefficients of ESG rating performance in the central and western regions are 0.0163 and 0.0275, respectively, and ESG rating performance has a greater impact on enterprises in the central and western regions compared with the eastern region. The effect of ESG rating on total factor productivity of enterprises in resource-dependent cities and old industrial bases is not significant.