The expansion in factory activity in China was driven

China's factory activity grew at its fastest rate in more than two years in November, official data showed Thursday, as cheap credit and improving demand helped revive industry in the world's second-largest economy.

The better-than-expected pick-up in the closely watched purchasing managers' index (PMI) will provide fresh hope for stability after a long-running slowdown in economic growth.

The official PMI, which gauges conditions at factories and mines, came in at 51.7 in November, its highest since since July 2014, the National Bureau of Statistics (NBS) said. That beat October's 51.2 and was much better than the median forecast of 51.0 in a Bloomberg News survey of economists. 

Anything above 50 signals expanding activity while anything below suggests contraction. 

The expansion in factory activity was driven by an uptick in market demand, with production of consumer goods and high-tech equipment both accelerating, NBS analyst Zhao Qinghe said in a statement. 

But production "still has some difficulties" with raw materials and transportation costs rising for many companies, and sharp fluctuations in the yuan exchange rate making imports more costly, Zhao added.

China’s weakening currency helped lift new export orders, Zhao Yang of Nomura said in a note, adding that he expects the depreciation to continue, which “bodes well” for exports next year.

The resilience in manufacturing was largely due to stimulus measures, Julian Evans-Pritchard of Capital Economics said in a note.

But new restrictions on home buying may cause a correction in the property sector, and though economic activity will "hold up well for a few more months, we expect a renewed slowdown before long", he added. 

The private Caixin Purchasing Manager's Index, which focuses on smaller companies, also showed activity accelerating, albeit at a slower rate.

Its November reading of 50.9 represented a slight decline from its five-year-high of 51.2 the previous month, but was still "a robust pace", the Chinese financial magazine said in a joint statement with data compiler IHS Markit. 

The data showed China's industrial sector "continued to pick up steam", pointing to more inflationary pressures, Caixin analyst Zhong Zhengsheng said in the statement. 

"The Chinese economy continued to improve in November, although it lost some momentum compared to the previous month," Zhong added, noting that slightly weak employment and inventory figures suggested "the foundation of growth is not solid yet and investors have to remain vigilant about the risk of a downturn in coming months."

China is a vital driver of global growth, but its economy expanded only 6.9 percent in 2015 -- its weakest rate in a quarter of a century -- and has slowed further this year.