{"id":360517,"date":"2021-10-31T11:00:26","date_gmt":"2021-10-31T08:00:26","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-python-can-help-you-understand-the-friend-paradox\/"},"modified":"2021-10-31T11:00:26","modified_gmt":"2021-10-31T08:00:26","slug":"how-python-can-help-you-understand-the-friend-paradox","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-python-can-help-you-understand-the-friend-paradox\/","title":{"rendered":"#How Python can help you understand the &#8216;friend paradox&#8217;"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a38796f6e07e\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a38796f6e07e\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-python-can-help-you-understand-the-friend-paradox\/#Minimal_example\" >Minimal example<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-python-can-help-you-understand-the-friend-paradox\/#Analyze_Facebook_network\" >Analyze Facebook network<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-python-can-help-you-understand-the-friend-paradox\/#Visualize_the_influencers\" >Visualize the influencers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-python-can-help-you-understand-the-friend-paradox\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<p>&#8220;<strong>#How Python can help you understand the &#8216;friend paradox&#8217;<\/strong>&#8221;<\/p>\n<div>Do your friends, on average, have more friends than you? If you are an average person, there is a high chance that you have\u00a0<strong>fewer<\/strong>\u00a0friends than your friends.<\/p>\n<p>This is called the friendship paradox. This phenomenon states that most people have fewer friends than their friends have, on average.<\/p>\n<p>In this article, I will demonstrate why such a paradox exists, and whether we can find the paradox in <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">Facebook<\/a> data.<\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-1371364 size-full js-lazy\" alt=\"\" width=\"825\" height=\"712\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/1_aTaNnOvrhKPnBr3MIpgEGg.gif?\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Fneural%2F2021%2F10%2F31%2Fhow-to-use-python-to-figure-out-why-your-friends-have-more-friends-than-you%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: GIF by author\" data-title=\"Share GIF by author on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share GIF by author on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>GIF by author<\/figcaption><noscript><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-1371364 size-full\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/1_aTaNnOvrhKPnBr3MIpgEGg.gif?\" alt=\"\" width=\"825\" height=\"712\" srcset=\"\"\/><\/noscript><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Minimal_example\"><\/span>Minimal example<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To understand why the friend paradox exists, let\u2019s start with a minimal example. We will create a network of people. Two people are friends if they are listed in the same Python tuple.<\/p>\n<p><iframe loading=\"lazy\" title=\"Friendship Paradox\" src=\"https:\/\/cdn.embedly.com\/widgets\/media.html?src=https%3A%2F%2Fdatapane.com%2Fu%2Fkhuyentran1401%2Freports%2FaAMZMW3%2Ffriendship-paradox%2Fembed%2F%3Fblock_name%3Dsample&amp;display_name=Datapane&amp;url=https%3A%2F%2Fdatapane.com%2Fu%2Fkhuyentran1401%2Freports%2FaAMZMW3%2Ffriendship-paradox%2F%3Fblock_name%3Dsample&amp;image=https%3A%2F%2Fdatapane.com%2Fstatic%2Fpython_report_illustration.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=datapane\" width=\"960\" height=\"500\" frameborder=\"0\" scrolling=\"auto\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><span>Now we will use\u00a0<\/span><a rel=\"nofollow noopener\" target=\"_blank\" class=\"ea my\" href=\"https:\/\/towardsdatascience.com\/pyvis-visualize-interactive-network-graphs-in-python-77e059791f01\">Pyvis<\/a><span>\u00a0to visualize the network.<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-1371046 aligncenter js-lazy\" alt=\"\" width=\"677\" height=\"53\" sizes=\"auto, (max-width: 677px) 100vw, 677px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.28.15.png\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.28.15.png 677w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.28.15-280x22.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.28.15-270x21.png 270w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.28.15-540x42.png 540w\"\/><noscript><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-1371046 aligncenter\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.28.15.png\" alt=\"\" width=\"677\" height=\"53\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.28.15.png 677w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.28.15-280x22.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.28.15-270x21.png 270w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.28.15-540x42.png 540w\"\/><\/noscript><\/figure>\n<p><iframe loading=\"lazy\" title=\"Friendship Paradox\" src=\"https:\/\/cdn.embedly.com\/widgets\/media.html?src=https%3A%2F%2Fdatapane.com%2Fu%2Fkhuyentran1401%2Freports%2FaAMZMW3%2Ffriendship-paradox%2Fembed%2F%3Fblock_name%3Dsample_edges&amp;display_name=Datapane&amp;url=https%3A%2F%2Fdatapane.com%2Fu%2Fkhuyentran1401%2Freports%2FaAMZMW3%2Ffriendship-paradox%2F%3Fblock_name%3Dsample_edges&amp;image=https%3A%2F%2Fdatapane.com%2Fstatic%2Fpython_report_illustration.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=datapane\" width=\"960\" height=\"700\" frameborder=\"0\" scrolling=\"auto\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>If you move the nodes around, you can see that Ben is the center of the circle of friends.<\/p>\n<p>We are interested in finding <strong>what percentage of people in this network have fewer friends than their friends do on average<\/strong>. We will create multiple functions that help us answer this question. The functions are:<\/p>\n<ul>\n<li>Get friends of a specific person:<\/li>\n<\/ul>\n<p><span>For example, Lauren\u2019s friends are:<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-1371048 aligncenter js-lazy\" alt=\"\" width=\"681\" height=\"69\" sizes=\"auto, (max-width: 681px) 100vw, 681px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.31.49.png\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.31.49.png 681w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.31.49-280x28.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.31.49-270x27.png 270w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.31.49-540x55.png 540w\"\/><noscript><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-1371048 aligncenter\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.31.49.png\" alt=\"\" width=\"681\" height=\"69\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.31.49.png 681w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.31.49-280x28.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.31.49-270x27.png 270w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.31.49-540x55.png 540w\"\/><\/noscript><\/figure>\n<\/p>\n<ul>\n<li><span>Get the numbers of friends a specific person has:<\/span><\/li>\n<\/ul>\n<p><figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1371049 js-lazy\" alt=\"\" width=\"677\" height=\"141\" sizes=\"auto, (max-width: 677px) 100vw, 677px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.33.21.png\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.33.21.png 677w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.33.21-280x58.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.33.21-270x56.png 270w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.33.21-540x112.png 540w\"\/><noscript><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1371049\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.33.21.png\" alt=\"\" width=\"677\" height=\"141\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.33.21.png 677w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.33.21-280x58.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.33.21-270x56.png 270w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.33.21-540x112.png 540w\"\/><\/noscript><\/figure>\n<\/p>\n<p id=\"e62a\" class=\"jy jz gj ka b hi ks jf kc hl kt jj ke kf ku kh ki kj kv kl km kn kw kp kq kr gc hg\" data-selectable-paragraph=\"\">The result shows that Khuyen has 3 friends and Ben has 5 friends.<\/p>\n<ul class=\"\">\n<li id=\"83f8\" class=\"jy jz gj ka b hi ks jf kc hl kt jj ke kf ku kh ki kj kv kl km kn kw kp kq kr ol om on hg\" data-selectable-paragraph=\"\">Get the number of friends a person\u2019s friends have on average:<\/li>\n<\/ul>\n<p><figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1371052 js-lazy\" alt=\"\" width=\"675\" height=\"72\" sizes=\"auto, (max-width: 675px) 100vw, 675px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.37.56.png\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.37.56.png 675w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.37.56-280x30.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.37.56-270x29.png 270w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.37.56-540x58.png 540w\"\/><noscript><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1371052\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.37.56.png\" alt=\"\" width=\"675\" height=\"72\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.37.56.png 675w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.37.56-280x30.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.37.56-270x29.png 270w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.37.56-540x58.png 540w\"\/><\/noscript><\/figure>\n<p><span>The output shows that the number of friends Lauren\u2019s friends have on average is 4, which is higher than the number of friends she has.<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-1371053 js-lazy\" alt=\"\" width=\"700\" height=\"466\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/friends-image.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/friends-image.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/friends-image-280x186.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/friends-image-203x135.jpg 203w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/friends-image-406x270.jpg 406w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Fneural%2F2021%2F10%2F31%2Fhow-to-use-python-to-figure-out-why-your-friends-have-more-friends-than-you%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Image by author\" data-title=\"Share Image by author on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Image by author on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Image by author<\/figcaption><noscript><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-1371053\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/friends-image.jpg\" alt=\"\" width=\"700\" height=\"466\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/friends-image.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/friends-image-280x186.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/friends-image-203x135.jpg 203w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/friends-image-406x270.jpg 406w\"\/><\/noscript><\/figure>\n<p id=\"596a\" class=\"jy jz gj ka b hi ks jf kc hl kt jj ke kf ku kh ki kj kv kl km kn kw kp kq kr gc hg\" data-selectable-paragraph=\"\">If we observe the picture above carefully, we can see that Ben\u2019s number of friends gives a boost to the number of friends Lauren\u2019s friends have on average.<\/p>\n<p id=\"d4f0\" class=\"jy jz gj ka b hi ks jf kc hl kt jj ke kf ku kh ki kj kv kl km kn kw kp kq kr gc hg\" data-selectable-paragraph=\"\">Since Ben has many friends, many of his friends will be in a similar situation as Lauren. In other words, the number of friends their friends have on average is higher than their number of friends because<span>\u00a0<\/span><strong class=\"ka gk\">one or two of their friends are the influencers.<\/strong><\/p>\n<ul class=\"\">\n<li id=\"d36d\" class=\"jy jz gj ka b hi ks jf kc hl kt jj ke kf ku kh ki kj kv kl km kn kw kp kq kr ol om on hg\" data-selectable-paragraph=\"\">Get the number of friends for all people in the network<\/li>\n<\/ul>\n<p><iframe loading=\"lazy\" title=\"Friendship Paradox\" src=\"https:\/\/cdn.embedly.com\/widgets\/media.html?src=https%3A%2F%2Fdatapane.com%2Fu%2Fkhuyentran1401%2Freports%2FaAMZMW3%2Ffriendship-paradox%2Fembed%2F%3Fblock_name%3Dnum_friends_sample&amp;display_name=Datapane&amp;url=https%3A%2F%2Fdatapane.com%2Fu%2Fkhuyentran1401%2Freports%2FaAMZMW3%2Ffriendship-paradox%2F%3Fblock_name%3Dnum_friends_sample&amp;image=https%3A%2F%2Fdatapane.com%2Fstatic%2Fpython_report_illustration.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=datapane\" width=\"960\" height=\"500\" frameborder=\"0\" scrolling=\"auto\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>In the table above,<\/p>\n<ul>\n<li>The column <strong>num_friends<\/strong> shows the number of friends a person has.<\/li>\n<li>The column <strong>avg_friends_of_friends<\/strong> shows the number of friends a person\u2019s friends have on average.<\/li>\n<li>The column <strong>friends_have_more_friends<\/strong> indicates whether a person\u2019s friends have more friends than himself\/herself on average.<\/li>\n<\/ul>\n<p>Let\u2019s find out what percentage of people in the network have fewer friends than their friends have on average.<\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-1371056 aligncenter js-lazy\" alt=\"\" width=\"682\" height=\"60\" sizes=\"auto, (max-width: 682px) 100vw, 682px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.51.51.png\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.51.51.png 682w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.51.51-280x25.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.51.51-270x24.png 270w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.51.51-540x48.png 540w\"\/><noscript><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-1371056 aligncenter\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.51.51.png\" alt=\"\" width=\"682\" height=\"60\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.51.51.png 682w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.51.51-280x25.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.51.51-270x24.png 270w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.51.51-540x48.png 540w\"\/><\/noscript><\/figure>\n<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Analyze_Facebook_network\"><\/span>Analyze Facebook network<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/snap.stanford.edu\/data\/ego-Facebook.html\">The Facebook data<\/a> consists of friend lists from Facebook. Facebook data was collected from survey participants, and the users in this data have been anonymized.<\/p>\n<p>You can <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/snap.stanford.edu\/data\/facebook_combined.txt.gz\">download the data from here<\/a>. After <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">download<\/a>ing the data, unzip and save it as <strong>facebook_combined.txt<\/strong><\/p>\n<p><iframe loading=\"lazy\" title=\"Friendship Paradox\" src=\"https:\/\/cdn.embedly.com\/widgets\/media.html?src=https%3A%2F%2Fdatapane.com%2Fu%2Fkhuyentran1401%2Freports%2FaAMZMW3%2Ffriendship-paradox%2Fembed%2F%3Fblock_name%3Dnetwork&amp;display_name=Datapane&amp;url=https%3A%2F%2Fdatapane.com%2Fu%2Fkhuyentran1401%2Freports%2FaAMZMW3%2Ffriendship-paradox%2F%3Fblock_name%3Dnetwork&amp;image=https%3A%2F%2Fdatapane.com%2Fstatic%2Fpython_report_illustration.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=datapane\" width=\"960\" height=\"500\" frameborder=\"0\" scrolling=\"auto\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><span>We will use the previous functions to get the number of friends people in the network have.<\/span><\/p>\n<p><iframe loading=\"lazy\" title=\"Friendship Paradox\" src=\"https:\/\/cdn.embedly.com\/widgets\/media.html?src=https%3A%2F%2Fdatapane.com%2Fu%2Fkhuyentran1401%2Freports%2FaAMZMW3%2Ffriendship-paradox%2Fembed%2F%3Fblock_name%3Dnum_friends&amp;display_name=Datapane&amp;url=https%3A%2F%2Fdatapane.com%2Fu%2Fkhuyentran1401%2Freports%2FaAMZMW3%2Ffriendship-paradox%2F%3Fblock_name%3Dnum_friends&amp;image=https%3A%2F%2Fdatapane.com%2Fstatic%2Fpython_report_illustration.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=datapane\" width=\"960\" height=\"700\" frameborder=\"0\" scrolling=\"auto\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><span>Let\u2019s find out what percentage of people in the network have fewer friends than their friends have on average.<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-1371057 aligncenter js-lazy\" alt=\"\" width=\"679\" height=\"59\" sizes=\"auto, (max-width: 679px) 100vw, 679px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.55.38.png\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.55.38.png 679w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.55.38-280x24.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.55.38-270x23.png 270w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.55.38-540x47.png 540w\"\/><noscript><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-1371057 aligncenter\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.55.38.png\" alt=\"\" width=\"679\" height=\"59\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.55.38.png 679w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.55.38-280x24.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.55.38-270x23.png 270w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/Screenshot-2021-10-25-at-15.55.38-540x47.png 540w\"\/><\/noscript><\/figure>\n<p>87% of people in the network have fewer friends than their friends have on average!<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Visualize_the_influencers\"><\/span><strong>Visualize the influencers<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Which nodes are the influencers in the network? Let\u2019s visualize them using Pyvis.<br \/>Start with adding nodes to the network.<\/p>\n<p>We will define influencers as those who have more friends than their friends have on average. We will mark the nodes that are defined as influencers in red.<\/p>\n<p>Add edges and show the network graph:<\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-1371364 size-full js-lazy\" alt=\"\" width=\"825\" height=\"712\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/1_aTaNnOvrhKPnBr3MIpgEGg.gif?\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Fneural%2F2021%2F10%2F31%2Fhow-to-use-python-to-figure-out-why-your-friends-have-more-friends-than-you%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: GIF by author\" data-title=\"Share GIF by author on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share GIF by author on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>GIF by author<\/figcaption><noscript><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-1371364 size-full\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/1_aTaNnOvrhKPnBr3MIpgEGg.gif?\" alt=\"\" width=\"825\" height=\"712\" srcset=\"\"\/><\/noscript><\/figure>\n<p>As we can see, the red nodes (people who have more friends than their friends have on average) tend to be in the center of the graph. If we move a red node, many blue nodes will move with it. This indicates that these red nodes are the influencers of one or two subgroups in the network.<\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-1371545 size-full js-lazy\" alt=\"\" width=\"963\" height=\"601\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/1_zWUPcMqSngJ7n1HLLgb1aA.gif?\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Fneural%2F2021%2F10%2F31%2Fhow-to-use-python-to-figure-out-why-your-friends-have-more-friends-than-you%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: GIF by author\" data-title=\"Share GIF by author on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share GIF by author on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>GIF by author<\/figcaption><noscript><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-1371545 size-full\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/1_zWUPcMqSngJ7n1HLLgb1aA.gif?\" alt=\"\" width=\"963\" height=\"601\" srcset=\"\"\/><\/noscript><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Congratulations! You have just learned what the friend paradox is, and how to observe this paradox in Facebook data using Python. I hope this article will give you the motivation to observe other paradoxes around you using visualization and data <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/sciencee\/\" data-internallinksmanager029f6b8e52c=\"5\" title=\"Science\" target=\"_blank\" rel=\"noopener\">science<\/a> techniques.<\/p>\n<p>Feel free to fork and play with the code for this article <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/khuyentran1401\/Data-science\/blob\/master\/visualization\/friend_paradox\/facebook_network.ipynb\">in this repo<\/a>.<\/p>\n<p><em>This article was originally published on Towards Data Science, you can <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/towardsdatascience.com\/observe-the-friend-paradox-in-facebook-data-using-python-314c23fd49e4\">find it here<\/a>. Khuyen writes about basic data science concepts and enjoys playing with different algorithms and data science tools. You can connect with them on <a rel=\"nofollow noopener\" target=\"_blank\" class=\"ea my\" href=\"https:\/\/www.linkedin.com\/in\/khuyen-tran-1401\/\">LinkedIn<\/a>\u00a0and\u00a0<a rel=\"nofollow noopener\" target=\"_blank\" class=\"ea my\" href=\"https:\/\/twitter.com\/KhuyenTran16\">Twitter<\/a>.<\/em><\/p>\n<\/div>\n<p><script async src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong>\n<\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/thenextweb.com\/news\/how-to-use-python-to-figure-out-why-your-friends-have-more-friends-than-you\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How Python can help you understand the &#8216;friend paradox&#8217;&#8221; Do your friends, on average, have more friends than you? If you are an average person, there is a high chance that you have\u00a0fewer\u00a0friends than your friends. This is called the friendship paradox. This phenomenon states that most people have fewer friends than their friends have,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":360518,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/img-cdn.tnwcdn.com\/image\/neural?filter_last=1&fit=1280,640&url=https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/10\/python-friends.jpg&signature=ca931c53e750357604c32928bdd235a0","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-360517","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/360517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=360517"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/360517\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/360518"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=360517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=360517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=360517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}