Based on the Lasso algorithm and a bidirectional fixed multiple linear regression model, this study comprehensively investigates the impact of macro and micro factors on the credit spread of ESG bonds in China. Research has shown that the credit spread of ESG bonds is negatively correlated with macro factors such as regional per capita GDP, local fiscal revenue, money supply, stock market returns, as well as micro factors such as total issuance amount, entity rating, debt rating, guaranteed delivery, state-owned equity certification, and green certification. Meanwhile, the credit spread is positively correlated with factors such as RMB exchange rate, fuel oil price, and urban investment bond certification. Further heterogeneity analysis indicates that ESG bonds are more significantly impacted by external factors after the epidemic, and the safety of state-owned bonds is further highlighted. The default rate of ESG urban investment bonds in the southwest region is relatively high, and the key to reducing their credit spread is to obtain green certification for establishing a positive market image. The above research conclusions provide important references for optimizing the bond pricing mechanism and reasonably evaluating the risks of ESG concept financing projects.