<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by James Armah on Medium]]></title>
        <description><![CDATA[Stories by James Armah on Medium]]></description>
        <link>https://medium.com/@KC-James?source=rss-cbd376ac3874------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Qks7MV-1lzyyioAP</url>
            <title>Stories by James Armah on Medium</title>
            <link>https://medium.com/@KC-James?source=rss-cbd376ac3874------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 23:06:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@KC-James/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A story on smartphone market share evolution]]></title>
            <link>https://medium.com/@KC-James/a-story-on-smartphone-market-share-evolution-64e1da33c942?source=rss-cbd376ac3874------2</link>
            <guid isPermaLink="false">https://medium.com/p/64e1da33c942</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[data-storytelling]]></category>
            <category><![CDATA[market-share]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[smartphones]]></category>
            <dc:creator><![CDATA[James Armah]]></dc:creator>
            <pubDate>Thu, 01 Oct 2026 04:24:44 GMT</pubDate>
            <atom:updated>2026-10-01T04:24:44.645Z</atom:updated>
            <content:encoded><![CDATA[<p>Seeing all those iOS vs Android clashes online? Wondering who has the highest market share? Or who’s had it for a while now? Or factors contributing to that? Well, you’re at the right place. Let’s take a deeper dive into the issues:</p><p>You can refer to the information analysed here from the public <a href="https://public.flourish.studio/visualisation/30112780/">Flourish Studio</a> and the <a href="https://youtu.be/ARkiN2PRh24">YouTube video</a> I made earlier in this series.</p><p>Oh, that’s right, the dataset is also available readily <a href="https://www.kaggle.com/datasets/kingjesse/smartphones-by-market-share">here</a>; credit to <a href="https://gs.statcounter.com/vendor-market-share/mobile/worldwide">StatCounter Global Stats</a></p><p>Disclaimer: All analysis here is based on information inferred from the infographic in the YouTube video/Flourish Studio links shared above.</p><ol><li>In early <strong>2010</strong>, Nokia commanded nearly <strong>40%</strong> of the global mobile market share before touchscreens triggered a rapid industry shift.<br>This is what the smartphone market share looked like in <strong>April 2010</strong>:<br><strong>Nokia:</strong> <em>38%</em><br><strong>RIM (BlackBerry):</strong> <em>16%</em><br><strong>Apple:</strong> <em>33%</em><br><strong>Sony:</strong> <em>8%</em><br><strong>Samsung:</strong> <em>2%</em></li><li>In <strong>January</strong> <strong>2012</strong>, we can observe from the infographic that touchscreen technology is on the rise, with <br>Nokia dropped to <strong>37% </strong>market share.<br>Apple was also at around <strong>30% market share.</strong><br>Samsung surged to <strong>15% (</strong>which is over three times the market share they had back in April 2010)<br>One key feature driving Samsung’s surge was the release of the Samsung Galaxy SIII in May. This smartphone sold 20 million units in its first 100 days, matching iPhone sales, and giving Android its first universally recognised flagship rival to Apple.</li><li><strong>As a result, by September 2013, Samsung</strong> had claimed the #1 global spot for the first time with <strong>26%</strong> market share, with <strong>Nokia</strong> dropping to #2 with <strong>22% and Apple</strong> following closely at <strong>21%</strong>. <strong>RIM (BlackBerry)</strong> shrank to <strong>4%</strong> (rebranding to BlackBerry Ltd earlier in the year in January 2013).</li><li>Let’s talk about <strong>May 2014 </strong><br>Samsung solidified its lead at <strong>33%</strong>.<br>At this point, Samsung had pioneered large-screen phones (the 5.1-inch Galaxy S5 and later, the 5.7-inch Galaxy Note 3). <br>At this time, Apple held <strong>24% </strong>of the market share (in early 2014, the iPhone 5S was the feature smartphone); however, in September 2014. Apple unveiled the iPhone 6 and 6 Plus (rivalling large-screen phones by Samsung). Apple sold 10 million units in its first 3 days and went on to sell over 220 million units, making the iPhone 6 the single best-selling smartphone model of all time. <br>Well, for Nokia, it had collapsed to <strong>14%</strong>. Its Windows Phone strategy had failed to attract budget buyers.</li><li>Fast forward to Autumn of 2016:<br>Samsung reaches its all-time high of <strong>34</strong>% global market share with the flagship smartphone Galaxy S7 and a re-look into the budget series (J and A series). Apple holds <strong>19% </strong>with the introduction of its flagship iPhone 7 series.</li><li>4 years onwards:<br>Samsung holds its <strong>31</strong>% market share, introducing the Galaxy Fold in 2019 and the Galaxy Z Flip in early 2020, opening a new product category for competitors. Samsung also consolidated its budget lineup into the current Galaxy A series (A50, A51, A71). Well, the Galaxy A51 became one of the world’s best-selling Android phones in 2020, providing high sales volume to defend Samsung’s global market lead during the onset of the COVID-19 pandemic. <br>Apple surges to<strong> 26</strong>% market share with the introduction of the iPhone X in November 2017 and iPhone 11 in late 2019. Well, particularly the iPhone 11, since a reduction in price as compared to its predecessor (iPhone X) spurred upgrade cycles in early 2020, boosting Apple’s market share. <br>Huawei! Let’s talk about Huawei.<strong> </strong>Huawei peaks at <strong>11%</strong> market share to hold the #3 global position. Huawei partnered with Leica to release the P20 Pro in 2018 and the P30 Pro in 2019. These devices set standards for mobile imaging. However, sanctions from the US government prevented American companies from doing business with Huawei from May 2019 onwards. This led to a decline in Huawei’s international sales.<br><strong>While </strong>Huawei faced friction, Xiaomi expanded rapidly across India and Europe to reach 8% global market share by April 2020. By selling flagship-level processors at near-cost prices through Redmi (a sub-brand), Xiaomi became the number 1 smartphone brand in India in 2017 and rapidly captured market share across Western Europe.</li><li>May 2021<br>Samsung drops in market share to <strong>28</strong>%, whereas Apple retains its market share of<strong> 26</strong>% with the release of the iPhone 12 with 5G. Xiaomi emerged as the primary beneficiary of Huawei’s decline in Western Europe, South Asia, and Latin America. By combining aggressive hardware specs with low profit margins via its <strong>Redmi sub-brand</strong>, cementing its role as the top challenger behind Apple and Samsung.</li><li>April 2023<br>Apple overtakes Samsung for the top spot, reaching <strong>31%</strong> market share compared to Samsung’s <strong>26%</strong>. One key driver: Apple opened its first flagship retail store in India. India shifted from a pure budget market into one of Apple’s fastest-growing markets.</li><li>July 2026 (last month from the dataset used for the video) <br>Market share standings:<br><strong>Apple</strong>: <strong>32%</strong> market share<br><strong>Samsung:</strong> <strong>19%</strong> market share<br><strong>Xiaomi:</strong> <strong>10%</strong> market share<br><strong>Vivo:</strong> <strong>6</strong>%<br><strong>Oppo:</strong> <strong>6</strong>%<br><strong>Realme:</strong> <strong>4</strong>%<br><strong>Motorola:</strong> <strong>4</strong>%<br><strong>Google (Pixel):</strong> <strong>2</strong>%<br><strong>Transsion / Tecno / Infinix:</strong> <strong>~1.7</strong>%</li><li>Chinese brands <strong>Oppo, Vivo, OnePlus, and Realme</strong> share ownership under parent conglomerate <strong>BBK Electronics</strong>, combining for over 15% aggregate global market share by mid-2026.</li><li>Brands <strong>Tecno, Infinix, and itel</strong> belong to Shenzhen-based <strong>Transsion Holdings</strong>, which dominates emerging markets in Africa and South Asia.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64e1da33c942" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WHO dataset on COVID-19 analytics using PowerBI]]></title>
            <link>https://medium.com/@KC-James/who-dataset-on-covid-19-analytics-using-powerbi-ac66376b059a?source=rss-cbd376ac3874------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac66376b059a</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[power-bi]]></category>
            <category><![CDATA[covid19]]></category>
            <dc:creator><![CDATA[James Armah]]></dc:creator>
            <pubDate>Mon, 03 Feb 2025 09:56:40 GMT</pubDate>
            <atom:updated>2025-02-03T09:56:40.449Z</atom:updated>
            <content:encoded><![CDATA[<p>Setting the Stage: The Dataset<br>The dataset used in this article was obtained from <a href="https://data.who.int/dashboards/covid19/data?n=o">COVID-19 data.</a> The dataset used is also capped to September 08, 2024 as that was the day the dataset was obtained for the analytics. The PowerBI visualization for this analytic can be found <a href="https://app.powerbi.com/groups/me/reports/bb5a8202-6548-4681-8ff9-ef863cfe24df/5fbdbdc035d65b348087?experience=power-bi">here</a>. Below are subtle details that can be concluded from careful analysis of the visualization shared.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PCfX12faptsVj0VcVw8wtA.png" /><figcaption>Fig 1. The COVID-19 dashboard</figcaption></figure><p>What the Data Tells Us</p><ol><li>745 billion cases in total have been recorded between the periods of January 04, 2020 and September 08, 2024.</li><li>8 billion of these cases have been recorded as deaths, as such we have 745–8 = 737 billion cases which are either recovered or active cases from the dataset used.</li><li>Worldwide, COVID-19 has recorded a mortality rate of 1.11% so far.</li><li>Europe was the worst hit as it recorded 36.68% of all cumulative cases.</li><li>Russia led with accumulated deaths recorded (14.83%) in Europe and France led with accumulated cases recorded (13.45%)</li><li>COVID-19 cases peaked in 2023 whereas new cases peaked in 2022 recording 168,525,467 (21.64%) of cases across all 5 years of data records or capture.</li><li>2021 was the year with the highest new deaths and recording a mortality rate of 2.14%</li><li>Total deaths recorded over the period of data collection (top 7 regions/ countries) in the format country (Continent) — Estimation:<br>i. United States of America (AMR) — Over a billion<br>ii. Brazil (AMR) — Over 872 million<br>iii. India (SEAR) — Over 657 million<br>iv. Russia (EUR) — Over 445 million<br>v. Mexico (AMR) — Over 434 million<br>vi. Peru (AMR) — Over 292 million<br>vii. United Kingdom (EUR) — Over 286 million</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac66376b059a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Surface dive into unsupervised learning]]></title>
            <link>https://medium.com/@KC-James/surface-dive-into-unsupervised-learning-c90255f4a5e1?source=rss-cbd376ac3874------2</link>
            <guid isPermaLink="false">https://medium.com/p/c90255f4a5e1</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[unsupervised-learning]]></category>
            <dc:creator><![CDATA[James Armah]]></dc:creator>
            <pubDate>Sat, 30 Dec 2023 21:12:50 GMT</pubDate>
            <atom:updated>2023-12-30T21:12:50.625Z</atom:updated>
            <content:encoded><![CDATA[<h3>Intro to unsupervised learning</h3><p>Has AI become a buzzword? In essence, artificial Intelligence (AI) is a way of building computer systems to emulate human intelligence.</p><blockquote>In computer science, artificial intelligence (AI) is the field that deals with creating intelligent computer systems, or systems that display traits that humans identify as intelligence in human behaviour, such as language comprehension, learning, reasoning, problem-solving, and so on.<strong>- (Barr &amp; Feigenbaum, 1981)</strong></blockquote><p>Artificial intelligence may be divided into these areas: fuzzy logic, robotics, expert systems, machine learning, neural networks, and natural language processing (NLP). (<a href="https://www.analyticssteps.com/blogs/6-major-branches-artificial-intelligence-ai#google_vignette">https://www.analyticssteps.com/blogs/6-major-branches-artificial-intelligence-ai#google_vignette</a>)<br>When it comes to machine learning, there are three varieties: reinforcement learning, unsupervised machine learning, and supervised machine learning. <br>The main focus of this article is to examine unsupervised machine learning. An algorithm for machine learning that uses unlabeled data to train its data is known as <strong>unsupervised machine learning.</strong></p><h3>Basics of unsupervised learning</h3><p>Unsupervised learning algorithms find hidden relationships or patterns in the data without human assistance. Due to this ability and its capacity to identify patterns in data, it is the best option for exploratory data analysis, consumer segmentation, and picture recognition.<br>Let us consider a scenario where genes are grouped based on expression patterns to discover groups with similar biological functions. This is an illustrative case study for exploratory data analysis that may be explored with unsupervised learning models.</p><h3>Exploring unsupervised learning techniques</h3><ul><li>Clustering Algorithms<br>When working with unlabeled data, one way to find hidden patterns is to group the objects into clusters. One cluster is made up of objects with the best similarity, while another is made up of objects with little to no similarity. Various methods, such as K-means clustering, Hierarchical clustering, DBSCAN, Mean Shift, Agglomerative clustering, Gaussian Mixture Models, and others, can assist in achieving this, contingent upon the objectives of the study and the attributes of the data.</li><li>Dimensionality Reduction<br>When working with unlabeled data, the input variables may be too many to train. A dimensionality reduction algorithm is necessary to reduce the number of input variables. Reducing our data set from a relatively high number of variables to a reduced number is usually termed the degrees of freedom. When reducing the input variables, we must capture all relevant variables, which is very important. Dimensionality reduction is performed after the data has been cleaned and preprocessed.</li></ul><p>Real-world applications</p><p>There are quite some applications of unsupervised machine learning. This could include:<br>- Image compression and feature extraction<br>- Anomaly detection in cybersecurity<br>- Document clustering in text analysis<br>- Financial fraud detection<br>- Social network analysis</p><p>In the upcoming write-up, we will examine a deep dive into one of the applications.</p><p>Thank you for reading. I hope you found it insightful.</p><p>P.S: An old article was selected to define Artificial Intelligence to help users understand that the fundamental concept behind Artificial Intelligence has not changed even though many evolutionary techniques have emerged.</p><p>Happy new year in advance to all readers</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c90255f4a5e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basic implementation of a word cloud in Python]]></title>
            <link>https://medium.com/@KC-James/basic-implementation-of-a-word-cloud-in-python-8b2f9d92d381?source=rss-cbd376ac3874------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b2f9d92d381</guid>
            <category><![CDATA[python-word-cloud]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[word-cloud]]></category>
            <dc:creator><![CDATA[James Armah]]></dc:creator>
            <pubDate>Thu, 19 Oct 2023 21:52:27 GMT</pubDate>
            <atom:updated>2023-10-19T21:52:27.317Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>One crucial component of data analytics is data visualization. A visual representation is vital when evaluating data because it may reveal trends and patterns that are difficult to spot in the raw data analysis while also effectively communicating with stakeholders. Knowing how to visualize data is essential for deciphering complicated data, making it easier to grasp, and assisting in decision-making. One form of visualizing data is in the form of a word cloud.</p><h3>When to use Word Cloud visualization</h3><p>Have you ever wanted to view the most appearing words in a paragraph or a vast dataset to understand what the dataset is trying to communicate? Word Clouds are great tools that can be used to visualize data in such scenarios. In conclusion, you can use word clouds<br>- To analyse text and provide a quick overview of textual data, <br>- To market content, <br>- In SEOs to find the most commonly used keywords, <br>- In stakeholder presentations to bring more clarity.<br>- To monitor brands mentioned on social media<br>- For artistic purposes</p><h4>Required libraries for word cloud visualization in Python</h4><ol><li>nltk.tokenize<br>When creating a word cloud, it is necessary to divide all lists into substrings taking into account punctuations in the string. word_tokenize, imported from nltk.tokenize will help us achieve this. <br><a href="https://www.nltk.org/api/nltk.tokenize.html">A link to the official documentation for further reading</a>.</li><li>nltk.corpus<br>Since the text/ string data we have is now subdivided into lists, it is structured, and we can refer to it as a “corpus”. In our corpus, we would like to remove everyday English words (stopwords) such as conjunctions (and, but, or), pronouns (he, she, they), and others so that we can generate a word cloud devoid of repetitive everyday English keywords such as these. The stopwords module of the nltk.corpus package can be imported to achieve this. <br><a href="https://www.nltk.org/api/nltk.corpus.html">A link to the official documentation for further reading.</a></li><li>wordcloud<br>To generate the word cloud on the string data available, the wordcloud package can be used to achieve this. <br><a href="https://pypi.org/project/wordcloud/">A link to the official documentation for further reading and installation.</a></li><li>matplotlib<br>Matplotlib.pyplot is the package that will be used to generate the plotted word cloud so it is visible to us. <br><a href="https://pypi.org/project/matplotlib/">More can be read on here on matplotlib</a></li></ol><p>P.S: nltk stands for Natural Language Toolkit</p><h3><strong>Step-by-step code walkthrough and analysis</strong></h3><p>The code for implementing this:</p><pre>from nltk.tokenize import word_tokenize<br>from nltk.corpus import stopwords<br>from wordcloud import WordCloud<br>import matplotlib.pyplot as plt<br>#Function to generate a word cloud from user input text<br>def generate_wordcloud(text):<br>    words = word_tokenize(text)<br>    <br>    #Let&#39;s check the word count<br>    word_count = len(words)<br>    min_word_count = 25 #Setting minimum word count to be 25<br>    if word_count &lt; min_word_count:<br>        print(f&quot;Insufficient words. Please type at least {min_word_count} words.&quot;)<br>        return<br>    <br>    #Removing stopwords<br>    stop_words = set(stopwords.words(&#39;english&#39;))<br>    words = [word.lower()<br>            for word in words<br>                if word.isalnum() and word.lower() not in stop_words]<br>    #Creating a word frequency<br>    word_freq = {}<br>    for word in words:<br>        if word in word_freq:<br>            word_freq[word] += 1<br>        else:<br>            word_freq[word] = 1<br>    #Generating the word cloud<br>    wordcloud = WordCloud (width=800, height=400, background_color=&#39;white&#39;).generate_from_frequencies(word_freq)<br>    <br>    #Displaying the word cloud<br>    plt.figure(figsize=(10, 5)) #width and height<br>    plt.imshow(wordcloud, interpolation=&#39;bilinear&#39;)<br>    plt.axis(&quot;off&quot;)<br>    plt.show()<br><br><br>#Getting the user input <br>user_input = input(&quot;Enter your text: &quot;)<br><br>if user_input:<br>    generate_wordcloud(user_input)<br>else:<br>    print(&quot;No input provided&quot;)</pre><p>User input is accepted to the user_input variable. Since we need to check for user input, we can use an if statement like in the code above, when no texts are detected, print out “No input provided”.<br>It’s also very substantial to get some number of words so we can make the best out of our word cloud. To implement this, we pass our tokenized text through a word count if statement, where the tokenized texts should exceed a threshold (in this case 25) before a word cloud is generated otherwise, it throws an error to the user “Insufficient words”.<br>As mentioned, the module “stopwords” is imported to remove common English words before the word cloud generation. The “stopwords.words(‘english’)” part retrieves the list of English stopwords from ‘nltk’. A thorough explanation of the stopwords removal code block:<br>word.lower() turns all tokenized text to lowercase making sure no two same words are treated differently. For instance, “This” and “this”.<br>With “if word.isalnum() and word.lower() not in stop_words”, we’re basically saying keep this word only if it consists of letters and numbers and is not in the list of stopwords. Up next, we create an empty dictionary to store the frequency of the words. Then, loop through each word in the list of words and update its frequency in the dictionary. What is happening here is, we check if the word has already been encountered before. If the word is already in the dictionary, we increase its frequency count by 1, else we add it to the dictionary with a frequency count of 1.<br>The next line is essentially creating a word cloud visualization based on the frequencies of words in a text.<br>On the display word cloud section, the first line sets the size of the figure for the plot. The second line displays the word cloud image within the plot.<br>The `interpolation=’bilinear’` parameter specifies the <a href="https://matplotlib.org/stable/gallery/images_contours_and_fields/interpolation_methods.html">interpolation method</a> used to display the image. The third line removes the axis and border around the plot. The fourth line displays the entire plot within the word cloud.</p><h3>Conclusion</h3><p>This has been a very brief and concise explanation of the basic word cloud generation. Hopefully, it has been insightful to all readers. You can probably expand on this with a game where users have some number of tries to figure out music from a selected genre through the word cloud visualization.<br>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b2f9d92d381" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basic Customer Segmentation use case with SQL]]></title>
            <link>https://medium.com/@KC-James/basic-customer-segmentation-use-case-with-sql-1dc53787942f?source=rss-cbd376ac3874------2</link>
            <guid isPermaLink="false">https://medium.com/p/1dc53787942f</guid>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[customer-segmentation]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[James Armah]]></dc:creator>
            <pubDate>Mon, 07 Aug 2023 23:19:40 GMT</pubDate>
            <atom:updated>2023-08-07T23:19:40.377Z</atom:updated>
            <content:encoded><![CDATA[<p>Businesses have access to more information than ever in today’s data-driven world. Segmenting consumer bases is one of the most beneficial data applications for businesses. Segmenting a customer base involves dividing them into smaller groups with similar requirements or traits. By researching these groups, companies may design more targeted marketing strategies that increase engagement and boost revenue.</p><p>As part of this article, we will examine a problem statement and then, using a given dataset, make predictions based on user segments generated from the dataset based on requirements.</p><p>Problem Statement:</p><p>“The Old Ticket” is a shop that is currently in debt and has realized that in order to boost revenue, sales must grow. To increase sales, they want to campaign targeted ads at top-buying customers. Their definition of top-buying customers is an individual with a higher annual income than the average and a higher spending score than three-fourths of the database’s total spending score.</p><p>Additionally, they added that getting the gender, age, annual income, and spending income of such customers will be instrumental to them in the final proposal we come up with.</p><p>A quick dive into the types of customer segmentation:</p><ul><li>Demographic segmentation: Establishing segments based on gender, income, age, occupation, nationality, marital status, and others.</li><li>Geographic segmentation: Establishing segments based on where customers live. These variables may include temperature, population, food habits, clothing, etc.</li><li>Psychographic segmentation: Establishing segments based on psychological variables such as personality, lifestyle, social status, activities, interests, opinions, attitudes, etc.</li><li>Behavioural segmentation: Establishing segments based on behaviours exhibited, such as types of products and contents consumed, the cadence of interactions with apps, websites, businesses and others.</li></ul><p>From the requirements specified, it is evident the segmentation to be performed on this challenge will be demographic segmentation.</p><p>The dataset for this exercise can be found <a href="https://www.kaggle.com/datasets/shwetabh123/mall-customers">here</a>.</p><p>To find the customers who have an annual income greater than the average annual income of all customers in the data table, we run the query:</p><pre>select * from table_name<br>where Annual_Income_k__ &gt;= (<br>  select avg(Annual_Income_k__)<br>  from table_name)</pre><p>This produces a data table consisting of all customers who have an annual income greater than the average income from the data given. But not only do we want to find this, but we also want to know the customers who have a spending score greater than three-fourths of the overall spending score of all customers. To know this, we run the query:</p><pre>select * from &#39;table-name&#39;<br>where Spending_Score_1_100 &gt;= 75<br>#75 because 75 is 3/4 of 100</pre><p>We then get a separate list of customers who have a spending score satisfying this requirement.</p><p>Let’s combine both queries to generate a list of customers passing both criteria (bearing in mind we are looking out for key variables such as gender, age, annual income and spending score to provide “The Old Ticker” with expert analysis)</p><pre>select Gender, count(*) as count<br>#To analyse the men and women who count as top-buying customers in the shop<br>from table_name<br>where Annual_Income__k__ &gt;= (<br>  select avg(Annual_Income__k__)<br>  from table_name)<br>and Spending_Score__1_100_ &gt;= 75<br>group by Gender</pre><p>From this query, we realise we have a total of 29 top-buying customers with 13 being men/ boys and 16 being women/ girls. To break down the analysis further, why not find the different age groups these top-buying customers belong to, so the Shop knows specific materials to bring in to attract customer interest? To do this, we run the query</p><pre>select<br>  Gender,<br>  case<br>    when Age &gt;= 20 and Age &lt; 30 then &#39;Twenties&#39;<br>    when Age &gt;= 30 and age &lt; 40 then &#39;Thirties&#39;<br>    when Age &gt;= 40 and Age &lt; 50 then &#39;Fourties&#39;<br>    else &#39;Others&#39;<br>  end as age_group,<br>  count(*) as count<br>from table_name<br>where Annual_Income__k__ &gt;= (<br>  select avg(Annual_Income__k__) <br>  from table_name) <br>and Spending_Score__1_100_ &gt;= 75<br>group by Gender, age_group;</pre><p>From this query run, we realise most of the top-buying customers are women and men in their thirties totalling 22 of the 29 top-buying customers.</p><p>Let’s go on to find their annual income range with the query below:</p><pre>select *,<br>  case<br>    when Annual_Income__k__ &lt; (<br>      select avg(Annual_Income__k__)<br>      from &#39;table-name&#39;)<br>      then &#39;Low Income&#39;<br>    when Annual_Income__k__ &gt;= (<br>      select avg(Annual_Income__k__)<br>      from &#39;table-name&#39; and Annual_Income__k__ &lt; (<br>        select max(Annual_Income__k__) from &#39;table-name&#39; )<br>      then &#39;Medium Income&#39;<br>    Else &#39;High Income&#39;<br>  end as income_segment<br>from &#39;table-name&#39;<br></pre><p>This generates a table of all top-buying customers with an additional column “Income_Segment” that divides the top-buying customers into either High, Medium or Low-income top-buying customers. Let’s go ahead and refine the query to find out the count of each of these to make an analysis on.</p><pre>select income_segment, count(*) AS count<br>from (<br>  select *,<br>    case <br>      when Annual_Income__k__ &lt; (<br>        select avg(Annual_Income__k__)<br>        from &#39;table-name&#39;)<br>        then &#39;Low Income&#39;<br>      when Annual_Income__k__ &gt;= (<br>        select avg(Annual_Income__k__)<br>        from &#39;table-name&#39; and Annual_Income__k__ &lt; (<br>          select max(Annual_Income__k__) from &#39;table-name&#39; )<br>        then &#39;Medium Income&#39;<br>      Else &#39;High Income&#39;<br>    End as income_segment<br>from &#39;table-name&#39;<br>) subquery<br>Group by income_segment</pre><p>From this query, we realise we have 10 Middle-Income earners, 1 High-Income earner and 18 Low-Income earners. In conclusion, we have 11 of our top-buying customers earning above the average income of the top-buying customer.</p><p>The goal is to perform this same analysis on customer spending scores and come out with 4 unique segments for all customers. The segments will be<br>1. P1 (high annual_income, high spending_score)<br>2. P2 (low annual_income, high spending_score)<br>3. P3 (high annual_income, low spending_score)<br>4. P4 (low annual_income, low spending_score)<br>where high means the customer is above average (medium or high earner or spender) in all cases.</p><p>Let’s go ahead to compute our top-buying customers against the average spending_score to know the various different spending segments</p><pre>select *,<br>  case<br>    when Spending_Score__1_100_ &lt; (<br>      select avg(Spending_Score__1_100_)<br>      from &#39;table-name&#39;)<br>      then &#39;Low Spender&#39;<br>    when Spending_Score__1_100_ &gt;= (<br>      select avg(Spending_Score__1_100_)<br>      from &#39;table-name&#39; and Spending_Score__1_100_ &lt; (<br>        select max(Spending_Score__1_100_) from &#39;table-name&#39; )<br>      then &#39;Medium Spender&#39;<br>    Else &#39;High Spender&#39;<br>  end as income_segment<br>from &#39;table-name&#39;</pre><p>To segment our users into the various customer segments (P1, P2, P3 &amp; P4), we can write the query:</p><pre>SELECT * <br>FROM (<br>  SELECT<br>    CASE<br>      WHEN Annual_Income__k__ &lt; <br>        (<br>          SELECT AVG(Annual_Income__k__) <br>          FROM &#39;table-name&#39; <br>        ) <br>        AND Spending_Score__1_100_ &lt; <br>        (<br>          SELECT AVG(Spending_Score__1_100_) <br>          FROM &#39;table-name&#39;<br>        ) <br>      THEN &#39;P4&#39;<br>      WHEN Annual_Income__k__ &gt;= <br>        (<br>          SELECT AVG(Annual_Income__k__) <br>          FROM &#39;table-name&#39;<br>        ) <br>        AND Spending_Score__1_100_ &gt;= <br>        (<br>          SELECT AVG(Spending_Score__1_100_) <br>          FROM &#39;table-name&#39;<br>        ) <br>      THEN &#39;P1&#39;<br>      WHEN Annual_Income__k__ &lt; <br>        (<br>          SELECT AVG(Annual_Income__k__) <br>          FROM &#39;table-name&#39;<br>        ) <br>        AND Spending_Score__1_100_ &gt;= <br>        (<br>          SELECT AVG(Spending_Score__1_100_) <br>          FROM &#39;table-name&#39;<br>        ) <br>      THEN &#39;P2&#39;<br>      WHEN Annual_Income__k__ &gt;= <br>      (<br>        SELECT AVG(Annual_Income__k__) <br>        FROM &#39;table-name&#39;<br>      ) <br>      AND Spending_Score__1_100_ &lt; <br>      (<br>        SELECT AVG(Spending_Score__1_100_) <br>        FROM &#39;table-name&#39;<br>      ) <br>    THEN &#39;P3&#39;<br>    END AS customer_segments<br>  FROM &quot;table-name&quot;<br>) subquery</pre><p>Running a count on all records/ shoppers, we come up with the fact that we have 48 P1 shoppers, 49 P2 shoppers, 54 P3 shoppers, and then 59 P4 shoppers. Based on the requirement given for the problem statement, the extracted top-buying customers can be segmented as well. Here go the various segments of top-buying customers: 5 P1 shoppers, 11 P2 shoppers, 6 P3 shoppers, and finally 7 P4 shoppers.</p><p>From this, businesses can take measures to know who to target and measures to be taken on the various segments. Perhaps, a separation on which and how many shoppers form premium shoppers.</p><p>Hope you found this write-up helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1dc53787942f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Scraping with BeautifulSoup in Python — A Beginner’s Guide]]></title>
            <link>https://medium.com/@KC-James/web-scraping-with-beautifulsoup-in-python-a-beginners-guide-96653f813e03?source=rss-cbd376ac3874------2</link>
            <guid isPermaLink="false">https://medium.com/p/96653f813e03</guid>
            <category><![CDATA[beautifulsoup]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[James Armah]]></dc:creator>
            <pubDate>Sat, 22 Apr 2023 21:15:00 GMT</pubDate>
            <atom:updated>2023-06-02T21:56:55.365Z</atom:updated>
            <content:encoded><![CDATA[<h3>Web Scraping with BeautifulSoup in Python — A Beginner’s Guide</h3><p>Hello readers, quick heads up and side note — This is my first time writing a Medium article, and I am excited to share my thoughts and ideas with you all. I would greatly appreciate any feedback or suggestions that you have to offer. I’m here to learn and grow as a writer, and your insights will be invaluable to me. Thank you for taking the time to read my article, and I hope you enjoy it!</p><h3><strong>What is Web Scraping?</strong></h3><p>Most people know scraping to be the act of removing the surface from something using a sharp edge or something rough. However, what is Web scraping?</p><p>Websites, just like rough or sharp edges, can be scraped to extract or eliminate small features.</p><p>With Web scraping, we assume websites to be the surfaces, and the sharp edges for scraping are the tools in this scenario. Web scraping is the automated extraction of data from websites using software or tools that can explore online pages and retrieve relevant information. These data can then be stored in a structured manner, such as a spreadsheet, database, or any other file format, for further analysis or processing.</p><p>Scraping the Web consists of three parts:</p><ul><li>obtaining the required links from the Internet,</li><li>extracting information from the links, and</li><li>storing the information in a well-structured CSV file.</li></ul><h3><strong>Uses of web scraping</strong></h3><p>Below are some uses of Web scraping.</p><p><strong>Market research:</strong> Users can use scraping to obtain information about rivals’ pricing, product offerings, and customer reviews for market research.</p><p><strong>Financial analysis</strong>: Web scraping can collect business data such as stock prices, financial statements, and economic indicators from websites to inform investing and trading choices.</p><p><strong>Job search:</strong> Users can use web scraping to collect job posts from multiple websites and job boards to simplify their job search experience.</p><p><a href="https://www.kaggle.com/code/kingjesse/web-scraping"><strong><em>Web Scraping for Job Search</em></strong></a><strong><em> → </em></strong>This Kaggle notebook contains two detailed samples of using web scraping for job search applications. One of the samples followed a <a href="https://youtu.be/XVv6mJpFOb0">freecodecamp tutorial</a>, which is also referenced below in the write-up.</p><h3><strong>Web Scraping, Web Crawling</strong></h3><p>Occasionally, we can be confused by both these words and use them interchangeably. However, what if there is an actual difference between web scraping and crawling?</p><p>Let us consider a deep dive, shall we:</p><p>Web crawling is an automated process of scanning the World Wide Web to index and collect information from online websites. Crawlers, spiders, and bots are software programs that perform this procedure.</p><p>A web crawler begins by accessing a seed URL, which serves as a starting point for following links to other online sites. The crawler then obtains information from the sites it has visited, such as the title, metadata, text content, and hyperlinks. Following the links from these pages, the crawler builds a network of interconnected pages that it may access.</p><p>From the above, we realize that web scraping is used to extract specific data from websites, whereas web crawling is used to discover and index web pages. Both web crawling and web scraping can be automated using software programs; however, they serve different purposes and require different tools and techniques.</p><p>It is important to note that web scraping can be a useful tool in the context of web crawling but is not a necessary component of the crawling process.</p><h3><strong>Scraping the data</strong></h3><p><strong>Pre-requisites</strong></p><p><strong><em>This write-up only covers scraping on local files and not on live/hosted URLs.</em></strong></p><p>Before proceeding to perform a scraping activity, the user should be familiar with these:</p><ul><li>Python to some level of extent (at least a basic beginner’s understanding with an understanding of fundamentals such as looping, branching, data types, and basic syntax)</li><li>HTML and CSS as scraping involves parsing HTML and CSS files</li><li>HTTP Requests (This is only when you are scraping a website and not a local file)</li><li>BeautifulSoup: Python library used for scraping.</li><li>Navigation of a web browser inspector as a tool to assist with scraping is a web browser developer tool. This will help identify the tags and elements to be scraped.</li><li>Data parsing such as web scraping usually involves retrieving messy or unstructured data that need to be cleaned and transformed into a usable format.</li></ul><p>Next, we will dive deeper into the library we use in this article for scraping.</p><h3><strong>BeautifulSoup library, its methods, and uses.</strong></h3><p>Beautiful Soup is a Python library used for parsing and extracting data from HTML and XML files. It supports several parsers, including lxml, html5lib, and the built-in Python parser. The library provides idiomatic ways of navigating, searching, and modifying the parse tree, which can save programmers hours or days of work [<a href="https://beautiful-soup-4.readthedocs.io/en/latest/">1</a>].</p><p>To use Beautiful Soup, developers first create a parse tree using a parser of their choice. They can then use Beautiful Soup’s API to navigate and search the tree. The API provides several methods for finding elements in the tree, such as find() and find_all().</p><p>The find() method returns the first element in the parse tree that matches the specified tag and attributes. The find_all() method returns a list of all elements in the parse tree that match the specified tag and attributes. Developers can also search for elements based on their text content using the find_all(text=…) method [<a href="https://blog.devgenius.io/introduction-to-beautiful-soup-a-python-library-for-web-scraping-21cacb9cf088">2</a>].</p><p>Beautiful Soup can be used for a variety of tasks, such as web scraping, data extraction, and screen scraping. It is commonly used to extract data from websites and web pages, which can then be used for various data analysis or machine learning tasks. Beautiful Soup can also be used to clean and transform data, making it a versatile tool for data manipulation in Python [<a href="https://realpython.com/beautiful-soup-web-scraper-python/">3</a>].</p><p>Overall, BeautifulSoup is a powerful and flexible library for parsing and extracting data from HTML and XML files. Its simple API and robust feature set make it a popular choice for web scraping and data extraction tasks in Python</p><p><strong>Scraping locally stored HTML templates and files</strong></p><ul><li>First, we will have to import the BeautifulSoup package and then open the HTML template or file to be scraped as an HTML file.</li></ul><pre>from bs4 import BeautifulSoup<br>with open(&#39;C:/Users/HP/D. Science/project_i/templatemo_556_catalog_z/index.html&#39;, &#39;r&#39;) as html_file:<br>    content = html_file.read()<br>    soup = BeautifulSoup(content, &#39;lxml&#39;)<br>    print (content)</pre><ul><li>We will have to know the information we will like to scrap from the website. In this case, we will be using the HTML file attached [<a href="https://templatemo.com/tm-556-catalog-z">4</a>]. Our main focus is to scrape the images posted, the dates posted and the number of views for each image.</li><li>The “find all” method of this library comes in handy at this moment when we want to view all div tags in the classes associated with images to directly target image data on the site.</li></ul><pre>images_html_tags = soup.find_all(&quot;div&quot;, class_ = &quot;col-xl-3 col-lg-4 col-md-6 col-sm-6 col-12 mb-5&quot;)<br>print (images_html_tags)</pre><ul><li>We realize from the structure of the site, views on images can be called distinctly using “span” tags.</li></ul><pre>views = soup.find_all(&quot;span&quot;, class_ = &quot;&quot;)</pre><ul><li>We iterate over the “span” tags to generate a list of all views of the images</li></ul><pre>for view in views:<br>    no_of_view = view.text<br>    print (no_of_view)</pre><ul><li>Finally, we are going to iterate over both scraping results for images and views.</li></ul><pre>for images in images_html_tags:<br>    image = images.figure.figcaption.h2.text<br>    date_posted = images.div.span.text<br>    print (f&#39;Images on {image} were posted on {date_posted} and have {no_of_view}&#39;)</pre><p><strong>Scraping live/hosted sites</strong></p><p>As mentioned earlier, this write-up only covers scraping on locally stored HTML files, for more practice on scraping on live/ hosted sites, kindly visit <a href="https://youtu.be/XVv6mJpFOb0"><strong>Freecodecamp tutorial on web scraping with Python.</strong></a></p><p>Hope you found this write-up helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96653f813e03" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>