Fewer people leaving the city and more foreign newcomers have helped erase pandemic losses, new census data shows.