What's the karmic cause for loneliness I'm wondering why some people have many friends (lasting friendship like friends since kindergarten to college)while some has almost none. 
I understand that it would depend on situations in present. But if there's effect from past, what would these be? From buddhism point of view.
Well you'll never know. From a Buddhism point of view, it could very well be a blessing in disguise:


  On one occasion a certain monk, a Vajjian princeling, was dwelling near Vesali in a forest thicket. And on that occasion an all-night festival was being held in Vesali. The monk — lamenting as he heard the resounding din of wind music, string music, &amp; gongs coming from Vesali, on that occasion recited this verse:
  
  I live in the wilderness
      all alone
  like a log cast away in the forest.
  On a night like this,
      who could there be
      more miserable
              than me?
  
  Then the devata inhabiting the forest thicket, feeling sympathy for the monk, desiring his benefit, desiring to bring him to his senses, approached him and addressed him with this verse:
  
  As you live in the wilderness all alone
  like a log cast away in the forest,
  many are those who envy you,
      as hell-beings do,
      those headed for heaven.
  
  The monk, chastened by the devata, came to his senses.
  ~~ SN 9.9 ~~