{"id":1642,"date":"2021-12-28T09:53:45","date_gmt":"2021-12-28T02:53:45","guid":{"rendered":"https:\/\/mintea.blog\/?p=1642"},"modified":"2021-12-28T11:37:06","modified_gmt":"2021-12-28T04:37:06","slug":"1642","status":"publish","type":"post","link":"https:\/\/mintea.blog\/?p=1642","title":{"rendered":"What is Customer Analytics and Why is it important (with demo by Python)"},"content":{"rendered":"<p><strong>What is Customer Analytics and Why is it important (with demo by Python)<\/strong><\/p>\n<p>This article was published as a part of the\u00a0<a href=\"https:\/\/datahack.analyticsvidhya.com\/contest\/data-science-blogathon-15\/\" target=\"_blank\" rel=\"noopener\">Data Science Blogathon<\/a><\/p>\n<p>Businesses and Companies have a lot of customers these days.\u00a0The number of customers widely vary. It might be in hundreds for a local grocery store, and it may be in millions for a national bank or an insurance company. Companies like Google and Facebook have users in the numbers of Billions. Knowing about these customers is important for any company. Knowing your customers well and understanding their interests, likes and dislikes can help any business maximise its profits and improve customer retention.<\/p>\n<p>What is Customer Analytics?<\/p>\n<p>Customer Analytics is a process of collecting, gathering and analyzing customer data across a wide range of channels, interactions, funnels and help businesses make better business decisions. Customer analytics help businesses make better strategies, build better products, and provide better services to the customers. Important steps in the customer analytics process are data collection, data segmentation, visualization, modelling etc. Companies can use customer analytics for Direct marketing, better brand positioning and better customer relationship management. With proper analysis, one can provide a better experience to the customers, and make them stick to the brand. The likes and dislikes of the majority of customers can make or break a brand\/ product.\u00a0So, knowing customer habits are important and a well-implemented Customer Analytics strategy helps in predicting customer behaviour.<\/p>\n<p>Data Generated by customers:<\/p>\n<p>Customers of a company\/business generate a variety of data, but it can be grouped majorly into 4 types of data. They are:<\/p>\n<p><strong>Web Behaviour Data<\/strong><\/p>\n<p>People using a website generate a lot of data. Analysis of how people use a website, navigate and spend time on a particular page can help in a lot of ways to understand customer nature.<\/p>\n<p><strong>Transaction Data<\/strong><\/p>\n<p>Customer payments, transactions, purchases, etc have the most amount of data. This data will contain the customer ID, date, time, amount, product purchased, etc and so on. This data is the most sought-after as it provides great insights.<\/p>\n<p><strong>Product\/ Service usage data<\/strong><\/p>\n<p>Customers using a certain product, service by a company, also generate data. Let us say, the product is a fitness app, the app developer will get a lot of data which will include a mobile app on-screen time, data about usage of app features, in-app spends and so on. This will vary according to the product or service, but it can show valuable insights. If a certain product is being used a lot, it means it is popular and developers should make that feature better. Similarly, if something is not being used, it means it is not that popular. Such features might need to be removed or improved.<\/p>\n<p><strong>Customer created text data<\/strong><\/p>\n<p>Customers generate a lot of text data, it can be reviews, comments or other things. This type of data can help in understanding customer sentiments. Customers\u2019 attitudes towards the company can be understood.<\/p>\n<p>What is the importance of customer analytics?<\/p>\n<p>Customer analytics can help in numerous ways. An overview of customer habits can help in many ways. A well-defined strategy will help in customer acquisition, retention and active engagement with customers.<\/p>\n<p><strong>Customer Acquisition<\/strong><\/p>\n<p>Gaining new customers is a vital part of any business, without customers there will be no business. Effective marketing and sales strategies can help in gaining new customers. Creating personalized and viral marketing campaigns are easy with the correct data and insights.<\/p>\n<p><strong>Customer Satisfaction and Retention<\/strong><\/p>\n<p>Retaining customers is very important. By studying and understanding customer behaviour, we can perform predictive customer analytics. Techniques can be developed to engage with the retained customers and improve their satisfaction.<\/p>\n<p><strong>Lower costs and Improve Revenue<\/strong><\/p>\n<p>Better customer analytics can help lower acquisition costs and operating costs. Increased sales can also help in increased revenues. Consumers nowadays are very much price-conscious, informed, and selective. So brands and companies need to focus on selective targeting.<\/p>\n<p>What to do with Customer Analytics:<\/p>\n<p>Once we start tracking and collecting customer data, the data can be used to answer questions and deal with challenges. Better business decisions can be made. Using data, we can personalize content for users, focus on the promotion of campaigns to the right audience, and improve product development, sales, and marketing as a whole.<\/p>\n<p>Analysis of all types of customer channels should be performed, and we should understand how our service or product is helping\/ serving customers of different demographics. Customer Analytics can help to promote the brand in a better way by understanding customer-generated data like ratings, reviews, and feedback.<\/p>\n<p>While analysing customer data, customers which are at risk of being lost should be targeted to be retained to improve customer lifetime value. Customer segmentation can be implemented to better target customers across all channels and groups.<\/p>\n<p>An example with Python code:<\/p>\n<p>We will be working on a sample customer analytics project. The first part is Data collection and management. Our data taken is transactional data, where the transactions are bank transactions. One important part of data processing in such transactional data is the consolidation of customer profiles. This can be done by grouping together customer profiles by customer ID.<\/p>\n<p>Let us get started with the code, first we import the necessary libraries.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">numpy<\/span> <span style=\"color: #008800; font-weight: bold;\">as<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">np<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">pandas<\/span> <span style=\"color: #008800; font-weight: bold;\">as<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">pd<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">matplotlib.pyplot<\/span> <span style=\"color: #008800; font-weight: bold;\">as<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">plt<\/span>\r\n<span style=\"color: #333333;\">%<\/span>matplotlib inline\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">seaborn<\/span> <span style=\"color: #008800; font-weight: bold;\">as<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">sns<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">from<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">wordcloud<\/span> <span style=\"color: #008800; font-weight: bold;\">import<\/span> WordCloud\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">matplotlib.ticker<\/span> <span style=\"color: #008800; font-weight: bold;\">as<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">ticker<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">from<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">shapely.geometry<\/span> <span style=\"color: #008800; font-weight: bold;\">import<\/span> Point\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">geopandas<\/span> <span style=\"color: #008800; font-weight: bold;\">as<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">gpd<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">from<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">geopandas<\/span> <span style=\"color: #008800; font-weight: bold;\">import<\/span> GeoDataFrame\r\n<\/pre>\n<\/div>\n<p>Now, the necessary libraries are imported.<\/p>\n<p>Now, we read the data.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Reading the data<\/span>\r\ndata <span style=\"color: #333333;\">=<\/span> pd<span style=\"color: #333333;\">.<\/span>read_csv(<span style=\"background-color: #fff0f0;\">\"\/kaggle\/input\/anz-banking-data\/ANZ.csv\"<\/span>)\r\ndata<span style=\"color: #333333;\">.<\/span>head()\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"995\" height=\"505\" class=\"wp-image-1643\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/reading-the-data.jpeg\" alt=\"Reading the data\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/reading-the-data.jpeg 995w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/reading-the-data-300x152.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/reading-the-data-768x390.jpeg 768w\" sizes=\"auto, (max-width: 995px) 100vw, 995px\" \/><\/p>\n<p>The data has many features.<\/p>\n<p>Now, let us check the number of unique accounts in this data.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Checking the number of unique values<\/span>\r\ndata[<span style=\"background-color: #fff0f0;\">\"account\"<\/span>]<span style=\"color: #333333;\">.<\/span>nunique()\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p>100<\/p>\n<p>Now, we check the value count of the dates.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#number of date values<\/span>\r\ndata[<span style=\"background-color: #fff0f0;\">\"date\"<\/span>]<span style=\"color: #333333;\">.<\/span>value_counts()\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"696\" height=\"378\" class=\"wp-image-1644\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/check-the-value-count-of-the-dates.jpeg\" alt=\"check the value count of the dates\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/check-the-value-count-of-the-dates.jpeg 696w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/check-the-value-count-of-the-dates-300x163.jpeg 300w\" sizes=\"auto, (max-width: 696px) 100vw, 696px\" \/><\/p>\n<p>So, the date which had the most number of transactions is 28\/09\/2018.<\/p>\n<p>Now, we check it for customer IDs.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#the number of values for customer id<\/span>\r\ndata[<span style=\"background-color: #fff0f0;\">\"customer_id\"<\/span>]<span style=\"color: #333333;\">.<\/span>value_counts()\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"740\" height=\"377\" class=\"wp-image-1645\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/the-number-of-values-for-customer-id.jpeg\" alt=\"the number of values for customer id\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/the-number-of-values-for-customer-id.jpeg 740w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/the-number-of-values-for-customer-id-300x153.jpeg 300w\" sizes=\"auto, (max-width: 740px) 100vw, 740px\" \/><\/p>\n<p>From here, we can understand which customers had the most transactions and purchases.<\/p>\n<p>Such data can be used to profile and segment customers.<\/p>\n<p>Now, we check the column names.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Values of the columns<\/span>\r\ndata<span style=\"color: #333333;\">.<\/span>columns<span style=\"color: #333333;\">.<\/span>values\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"836\" height=\"209\" class=\"wp-image-1646\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/values-of-the-columns.jpeg\" alt=\"Values of the columns\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/values-of-the-columns.jpeg 836w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/values-of-the-columns-300x75.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/values-of-the-columns-768x192.jpeg 768w\" sizes=\"auto, (max-width: 836px) 100vw, 836px\" \/><\/p>\n<p>The dataset contains 12043 transactions for 100 customers who have one bank account each. The transactional period is from\u00a0<strong>01\/08\/2018 \u2013 31\/10\/2018<\/strong>\u00a0(92 days duration). The data entries are unique and have consistent formats for analysis. For each record\/row, information is complete for the majority of columns. Some columns contain missing data (blank or NA cells), which is likely due to the nature of the transaction. (i.e. merchants are not involved in InterBank transfers or Salary payments) It is also noticed that there are only 91 unique dates in the dataset, suggesting the transaction records for one day are missing (turned out to be 2018-08-16).<\/p>\n<p>Let us now analyze the data.<\/p>\n<p>Transaction Volume over the dates<\/p>\n<p>Now, we check the transaction volume over the dates.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Taking the sum of all transactions over the dates<\/span>\r\ndate_group <span style=\"color: #333333;\">=<\/span> data<span style=\"color: #333333;\">.<\/span>groupby(<span style=\"background-color: #fff0f0;\">'date'<\/span>)[<span style=\"background-color: #fff0f0;\">\"amount\"<\/span>]<span style=\"color: #333333;\">.<\/span>sum()<span style=\"color: #333333;\">.<\/span>reset_index()\r\n\r\n<span style=\"color: #888888;\">#Lineplot of the entire data<\/span>\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">16<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>))\r\nax<span style=\"color: #333333;\">=<\/span>sns<span style=\"color: #333333;\">.<\/span>lineplot(y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"amount\"<\/span>,x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"date\"<\/span>,data<span style=\"color: #333333;\">=<\/span>date_group)\r\nax<span style=\"color: #333333;\">.<\/span>xaxis<span style=\"color: #333333;\">.<\/span>set_major_locator(ticker<span style=\"color: #333333;\">.<\/span>LinearLocator(<span style=\"color: #0000dd; font-weight: bold;\">10<\/span>))\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1025\" height=\"404\" class=\"wp-image-1647\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/taking-the-sum-of-all-transactions-over-the-dates.jpeg\" alt=\"Taking the sum of all transactions over the dates\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/taking-the-sum-of-all-transactions-over-the-dates.jpeg 1025w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/taking-the-sum-of-all-transactions-over-the-dates-300x118.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/taking-the-sum-of-all-transactions-over-the-dates-768x303.jpeg 768w\" sizes=\"auto, (max-width: 1025px) 100vw, 1025px\" \/><\/p>\n<p>The number of transactions seems to vary on a weekly basis.<\/p>\n<p>Transaction Volume By Gender<\/p>\n<p>Now, let us see how it has varied for each gender.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Transaction volume over the dates by gender<\/span>\r\ngender_vol <span style=\"color: #333333;\">=<\/span> data[[<span style=\"background-color: #fff0f0;\">\"date\"<\/span>,<span style=\"background-color: #fff0f0;\">\"amount\"<\/span>,<span style=\"background-color: #fff0f0;\">\"gender\"<\/span>]]\r\ngender_data <span style=\"color: #333333;\">=<\/span> gender_vol<span style=\"color: #333333;\">.<\/span>groupby([<span style=\"background-color: #fff0f0;\">'date'<\/span>,<span style=\"background-color: #fff0f0;\">\"gender\"<\/span>])[<span style=\"background-color: #fff0f0;\">\"amount\"<\/span>]<span style=\"color: #333333;\">.<\/span>sum()<span style=\"color: #333333;\">.<\/span>reset_index()\r\n<span style=\"color: #888888;\">#Lineplot<\/span>\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">16<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>))\r\nax<span style=\"color: #333333;\">=<\/span>sns<span style=\"color: #333333;\">.<\/span>lineplot(y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"amount\"<\/span>,x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"date\"<\/span>,hue<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"gender\"<\/span>,data<span style=\"color: #333333;\">=<\/span>gender_data)\r\nax<span style=\"color: #333333;\">.<\/span>xaxis<span style=\"color: #333333;\">.<\/span>set_major_locator(ticker<span style=\"color: #333333;\">.<\/span>LinearLocator(<span style=\"color: #0000dd; font-weight: bold;\">10<\/span>))\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"407\" class=\"wp-image-1648\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/transaction-volume-over-the-dates-by-gender.jpeg\" alt=\"Transaction volume over the dates by gender\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/transaction-volume-over-the-dates-by-gender.jpeg 1000w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/transaction-volume-over-the-dates-by-gender-300x122.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/transaction-volume-over-the-dates-by-gender-768x313.jpeg 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/p>\n<p>We can see the generally male customers had more amount of transactions. This shows that male customers are more likely to spend more.<\/p>\n<p>Mean Transaction by Gender<\/p>\n<p>Let us check the mean transaction by gender.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Mean transaction over the dates by Gender<\/span>\r\ngender_mean <span style=\"color: #333333;\">=<\/span> data<span style=\"color: #333333;\">.<\/span>groupby([<span style=\"background-color: #fff0f0;\">\"date\"<\/span>,<span style=\"background-color: #fff0f0;\">\"gender\"<\/span>])[<span style=\"background-color: #fff0f0;\">\"amount\"<\/span>]<span style=\"color: #333333;\">.<\/span>mean()<span style=\"color: #333333;\">.<\/span>reset_index()\r\n<span style=\"color: #888888;\">#Lineplot for the data<\/span>\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">16<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>))\r\nax<span style=\"color: #333333;\">=<\/span>sns<span style=\"color: #333333;\">.<\/span>lineplot(y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"amount\"<\/span>,x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"date\"<\/span>,hue<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"gender\"<\/span>, data<span style=\"color: #333333;\">=<\/span>gender_mean)\r\nax<span style=\"color: #333333;\">.<\/span>xaxis<span style=\"color: #333333;\">.<\/span>set_major_locator(ticker<span style=\"color: #333333;\">.<\/span>LinearLocator(<span style=\"color: #0000dd; font-weight: bold;\">10<\/span>))\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"979\" height=\"413\" class=\"wp-image-1649\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-transaction-over-the-dates-by-gender.jpeg\" alt=\"Mean transaction over the dates by Gender\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-transaction-over-the-dates-by-gender.jpeg 979w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-transaction-over-the-dates-by-gender-300x127.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-transaction-over-the-dates-by-gender-768x324.jpeg 768w\" sizes=\"auto, (max-width: 979px) 100vw, 979px\" \/><\/p>\n<p>The data here also clearly shows, male customers have more value in transactions.<\/p>\n<p>Transaction Volume by merchant state<\/p>\n<p>Now, we check the transaction volume by merchant state.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Transaction volume sorted by states<\/span>\r\nmerchant_state <span style=\"color: #333333;\">=<\/span> data<span style=\"color: #333333;\">.<\/span>groupby([<span style=\"background-color: #fff0f0;\">\"date\"<\/span>,<span style=\"background-color: #fff0f0;\">\"merchant_state\"<\/span>])[<span style=\"background-color: #fff0f0;\">\"amount\"<\/span>]<span style=\"color: #333333;\">.<\/span>sum()<span style=\"color: #333333;\">.<\/span>reset_index()\r\n<span style=\"color: #888888;\">#Lineplot for the data<\/span>\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">16<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>))\r\nax<span style=\"color: #333333;\">=<\/span>sns<span style=\"color: #333333;\">.<\/span>lineplot(y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"amount\"<\/span>,x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"date\"<\/span>,hue<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"merchant_state\"<\/span>, data<span style=\"color: #333333;\">=<\/span>merchant_state)\r\nax<span style=\"color: #333333;\">.<\/span>xaxis<span style=\"color: #333333;\">.<\/span>set_major_locator(ticker<span style=\"color: #333333;\">.<\/span>LinearLocator(<span style=\"color: #0000dd; font-weight: bold;\">10<\/span>))\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"999\" height=\"611\" class=\"wp-image-1650\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/transaction-volume-sorted-by-states.jpeg\" alt=\"Transaction volume sorted by states\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/transaction-volume-sorted-by-states.jpeg 999w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/transaction-volume-sorted-by-states-300x183.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/transaction-volume-sorted-by-states-768x470.jpeg 768w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/transaction-volume-sorted-by-states-180x110.jpeg 180w\" sizes=\"auto, (max-width: 999px) 100vw, 999px\" \/><\/p>\n<p>Account Balance (mean of all customers) over the dates<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#mean account balance of all customers<\/span>\r\nacc_bal_mean<span style=\"color: #333333;\">=<\/span> data<span style=\"color: #333333;\">.<\/span>groupby([<span style=\"background-color: #fff0f0;\">\"date\"<\/span>,<span style=\"background-color: #fff0f0;\">'gender'<\/span>])[<span style=\"background-color: #fff0f0;\">\"balance\"<\/span>]<span style=\"color: #333333;\">.<\/span>mean()<span style=\"color: #333333;\">.<\/span>reset_index()\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">16<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>))\r\nax<span style=\"color: #333333;\">=<\/span>sns<span style=\"color: #333333;\">.<\/span>lineplot(y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"balance\"<\/span>,x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"date\"<\/span>,data<span style=\"color: #333333;\">=<\/span>acc_bal_mean)\r\nax<span style=\"color: #333333;\">.<\/span>xaxis<span style=\"color: #333333;\">.<\/span>set_major_locator(ticker<span style=\"color: #333333;\">.<\/span>LinearLocator(<span style=\"color: #0000dd; font-weight: bold;\">10<\/span>))\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"997\" height=\"394\" class=\"wp-image-1651\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-account-balance-of-all-customers.jpeg\" alt=\"mean account balance of all customers\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-account-balance-of-all-customers.jpeg 997w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-account-balance-of-all-customers-300x119.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-account-balance-of-all-customers-768x304.jpeg 768w\" sizes=\"auto, (max-width: 997px) 100vw, 997px\" \/><\/p>\n<p>Account balances are reducing in the month of August.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">plt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">16<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>))\r\nax<span style=\"color: #333333;\">=<\/span>sns<span style=\"color: #333333;\">.<\/span>lineplot(y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"balance\"<\/span>,x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"date\"<\/span>,hue<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"gender\"<\/span>,data<span style=\"color: #333333;\">=<\/span>acc_bal_mean)\r\nplt<span style=\"color: #333333;\">.<\/span>ylabel(<span style=\"background-color: #fff0f0;\">\"Balance [By gender]\"<\/span>)\r\nax<span style=\"color: #333333;\">.<\/span>xaxis<span style=\"color: #333333;\">.<\/span>set_major_locator(ticker<span style=\"color: #333333;\">.<\/span>LinearLocator(<span style=\"color: #0000dd; font-weight: bold;\">10<\/span>))\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1001\" height=\"400\" class=\"wp-image-1652\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/account-balances-are-reducing-in-the-month-of-augu.jpeg\" alt=\"Account balances are reducing in the month of August\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/account-balances-are-reducing-in-the-month-of-augu.jpeg 1001w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/account-balances-are-reducing-in-the-month-of-augu-300x120.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/account-balances-are-reducing-in-the-month-of-augu-768x307.jpeg 768w\" sizes=\"auto, (max-width: 1001px) 100vw, 1001px\" \/><\/p>\n<p>Male customers have more account balances.<\/p>\n<p>Account Balance (mean of all customers) for various states (all days average)<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Mean account balance over the states<\/span>\r\nacc_bal_state<span style=\"color: #333333;\">=<\/span> data<span style=\"color: #333333;\">.<\/span>groupby([<span style=\"background-color: #fff0f0;\">'merchant_state'<\/span>,<span style=\"background-color: #fff0f0;\">\"gender\"<\/span>])[<span style=\"background-color: #fff0f0;\">\"balance\"<\/span>]<span style=\"color: #333333;\">.<\/span>mean()<span style=\"color: #333333;\">.<\/span>reset_index()\r\n<span style=\"color: #888888;\">#Barplot for the data<\/span>\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">16<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>))\r\nsns<span style=\"color: #333333;\">.<\/span>barplot(x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"balance\"<\/span>, y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"merchant_state\"<\/span>, data<span style=\"color: #333333;\">=<\/span>acc_bal_state)\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1002\" height=\"394\" class=\"wp-image-1653\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-account-balance-over-the-states.jpeg\" alt=\"Mean account balance over the states\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-account-balance-over-the-states.jpeg 1002w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-account-balance-over-the-states-300x118.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-account-balance-over-the-states-768x302.jpeg 768w\" sizes=\"auto, (max-width: 1002px) 100vw, 1002px\" \/><\/p>\n<p>Northern Territory has the highest value and also the widest range of distribution.<\/p>\n<p>Barplot divided by gender.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Barplot sorted by gender<\/span>\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">16<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>))\r\nsns<span style=\"color: #333333;\">.<\/span>barplot(x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"balance\"<\/span>, y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"merchant_state\"<\/span>,hue<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"gender\"<\/span>, data<span style=\"color: #333333;\">=<\/span>acc_bal_state)\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"998\" height=\"399\" class=\"wp-image-1654\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-sorted-by-gender.jpeg\" alt=\"Barplot sorted by gender\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-sorted-by-gender.jpeg 998w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-sorted-by-gender-300x120.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-sorted-by-gender-768x307.jpeg 768w\" sizes=\"auto, (max-width: 998px) 100vw, 998px\" \/><\/p>\n<p>Total Transaction by Age<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">age_amount_sum<span style=\"color: #333333;\">=<\/span> data<span style=\"color: #333333;\">.<\/span>groupby([<span style=\"background-color: #fff0f0;\">'age'<\/span>,<span style=\"background-color: #fff0f0;\">\"gender\"<\/span>])[<span style=\"background-color: #fff0f0;\">\"amount\"<\/span>]<span style=\"color: #333333;\">.<\/span>sum()<span style=\"color: #333333;\">.<\/span>reset_index()\r\n<span style=\"color: #888888;\">#Barplot for the data<\/span>\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">16<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>))\r\nsns<span style=\"color: #333333;\">.<\/span>barplot(y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"amount\"<\/span>, x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"age\"<\/span>, data<span style=\"color: #333333;\">=<\/span>age_amount_sum)\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"995\" height=\"396\" class=\"wp-image-1655\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-for-the-data.jpeg\" alt=\"Barplot for the data\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-for-the-data.jpeg 995w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-for-the-data-300x119.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-for-the-data-768x306.jpeg 768w\" sizes=\"auto, (max-width: 995px) 100vw, 995px\" \/><\/p>\n<p>So, larger transactions are done by people in their youth and people in their middle ages, or is it actually the case?<\/p>\n<p>Let us split the data for males and females.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Barplot with hue parameter for gender<\/span>\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">16<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>))\r\nsns<span style=\"color: #333333;\">.<\/span>barplot(y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"amount\"<\/span>, x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"age\"<\/span>, hue<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"gender\"<\/span> ,data<span style=\"color: #333333;\">=<\/span>age_amount_sum)\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"992\" height=\"383\" class=\"wp-image-1656\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-with-hue-parameter-for-gender.jpeg\" alt=\"Barplot with hue parameter for gender\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-with-hue-parameter-for-gender.jpeg 992w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-with-hue-parameter-for-gender-300x116.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-with-hue-parameter-for-gender-768x297.jpeg 768w\" sizes=\"auto, (max-width: 992px) 100vw, 992px\" \/><\/p>\n<p>Males have had higher values.<\/p>\n<p>Mean Transaction by Age<\/p>\n<p>Mean transaction by age will show the actual overview of whether spending is more for some age group or simply those age groups have more population.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Mean of transaction values by age<\/span>\r\nage_amount_mean<span style=\"color: #333333;\">=<\/span> data<span style=\"color: #333333;\">.<\/span>groupby([<span style=\"background-color: #fff0f0;\">'age'<\/span>,<span style=\"background-color: #fff0f0;\">\"gender\"<\/span>])[<span style=\"background-color: #fff0f0;\">\"amount\"<\/span>]<span style=\"color: #333333;\">.<\/span>mean()<span style=\"color: #333333;\">.<\/span>reset_index()\r\n<span style=\"color: #888888;\">#Barplot for that data<\/span>\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">16<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>))\r\nsns<span style=\"color: #333333;\">.<\/span>barplot(y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"amount\"<\/span>, x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"age\"<\/span>, data<span style=\"color: #333333;\">=<\/span>age_amount_mean)\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1019\" height=\"404\" class=\"wp-image-1657\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-of-transaction-values-by-age-customer-analys.jpeg\" alt=\"Mean of transaction values by age (Customer Analysis)\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-of-transaction-values-by-age-customer-analys.jpeg 1019w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-of-transaction-values-by-age-customer-analys-300x119.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-of-transaction-values-by-age-customer-analys-768x304.jpeg 768w\" sizes=\"auto, (max-width: 1019px) 100vw, 1019px\" \/><\/p>\n<p>So, the value of transactions is fairly the same across all age groups.<\/p>\n<p>Let us split it by gender.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Barplot with Gender as a Hue<\/span>\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">16<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>))\r\nsns<span style=\"color: #333333;\">.<\/span>barplot(y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"amount\"<\/span>, x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"age\"<\/span>, hue<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"gender\"<\/span>, data<span style=\"color: #333333;\">=<\/span>age_amount_mean)\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"989\" height=\"408\" class=\"wp-image-1658\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-with-gender-as-a-hue-customer-analytics.jpeg\" alt=\"Barplot with Gender as a Hue (Customer Analytics)\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-with-gender-as-a-hue-customer-analytics.jpeg 989w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-with-gender-as-a-hue-customer-analytics-300x124.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/barplot-with-gender-as-a-hue-customer-analytics-768x317.jpeg 768w\" sizes=\"auto, (max-width: 989px) 100vw, 989px\" \/><\/p>\n<p>Debit-Credit Transaction Mean analysis By Gender<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Analysis of debit\/credit<\/span>\r\ndebit_credit<span style=\"color: #333333;\">=<\/span> data<span style=\"color: #333333;\">.<\/span>groupby([<span style=\"background-color: #fff0f0;\">\"movement\"<\/span>,<span style=\"background-color: #fff0f0;\">\"gender\"<\/span>])[<span style=\"background-color: #fff0f0;\">\"amount\"<\/span>]<span style=\"color: #333333;\">.<\/span>mean()<span style=\"color: #333333;\">.<\/span>reset_index()\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">8<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>))\r\nsns<span style=\"color: #333333;\">.<\/span>barplot(y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"amount\"<\/span>, x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"movement\"<\/span>, hue<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"gender\"<\/span>, data<span style=\"color: #333333;\">=<\/span>debit_credit)\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"748\" height=\"486\" class=\"wp-image-1659\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/debit-credit-transaction-mean-analysis-by-gender.jpeg\" alt=\"Debit-Credit Transaction Mean analysis By Gender\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/debit-credit-transaction-mean-analysis-by-gender.jpeg 748w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/debit-credit-transaction-mean-analysis-by-gender-300x195.jpeg 300w\" sizes=\"auto, (max-width: 748px) 100vw, 748px\" \/><\/p>\n<p>It is clear that people do credit transactions. Credit transactions are more popular in countries like the USA, Australia, etc.<\/p>\n<p>Debit-Credit Transaction Sum analysis By Age<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#By age<\/span>\r\ndc_age_total<span style=\"color: #333333;\">=<\/span> data<span style=\"color: #333333;\">.<\/span>groupby([<span style=\"background-color: #fff0f0;\">\"movement\"<\/span>,<span style=\"background-color: #fff0f0;\">\"age\"<\/span>])[<span style=\"background-color: #fff0f0;\">\"amount\"<\/span>]<span style=\"color: #333333;\">.<\/span>sum()<span style=\"color: #333333;\">.<\/span>reset_index()\r\n<span style=\"color: #888888;\">#Barplot according to age<\/span>\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">12<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>))\r\nsns<span style=\"color: #333333;\">.<\/span>barplot(y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"amount\"<\/span>, x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"movement\"<\/span>, hue<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"age\"<\/span>, data<span style=\"color: #333333;\">=<\/span>dc_age_total)\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"875\" height=\"674\" class=\"wp-image-1660\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/debit-credit-transaction-sum-analysis-by-agecusto.jpeg\" alt=\"Debit-Credit Transaction Sum analysis By Age(Customer analytics)\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/debit-credit-transaction-sum-analysis-by-agecusto.jpeg 875w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/debit-credit-transaction-sum-analysis-by-agecusto-300x231.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/debit-credit-transaction-sum-analysis-by-agecusto-768x592.jpeg 768w\" sizes=\"auto, (max-width: 875px) 100vw, 875px\" \/><\/p>\n<p>Debit-Credit Transaction Mean analysis By Age<\/p>\n<p>&nbsp;<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Mean transaction analysis by age<\/span>\r\ndc_age_mean<span style=\"color: #333333;\">=<\/span> data<span style=\"color: #333333;\">.<\/span>groupby([<span style=\"background-color: #fff0f0;\">\"movement\"<\/span>,<span style=\"background-color: #fff0f0;\">\"age\"<\/span>])[<span style=\"background-color: #fff0f0;\">\"amount\"<\/span>]<span style=\"color: #333333;\">.<\/span>mean()<span style=\"color: #333333;\">.<\/span>reset_index()\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">12<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>))\r\nsns<span style=\"color: #333333;\">.<\/span>barplot(y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"amount\"<\/span>, x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"movement\"<\/span>, hue<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"age\"<\/span>, data<span style=\"color: #333333;\">=<\/span>dc_age_mean)\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"844\" height=\"672\" class=\"wp-image-1661\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-transaction-analysis-by-age.jpeg\" alt=\"Mean transaction analysis by age\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-transaction-analysis-by-age.jpeg 844w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-transaction-analysis-by-age-300x239.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/mean-transaction-analysis-by-age-768x611.jpeg 768w\" sizes=\"auto, (max-width: 844px) 100vw, 844px\" \/><\/p>\n<p>Taking out the map coordinates<\/p>\n<p>Now, we will do some geospatial analysis by plotting the bank transaction points, on a map.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#taking relevant data<\/span>\r\ndf<span style=\"color: #333333;\">=<\/span>data[[<span style=\"background-color: #fff0f0;\">\"amount\"<\/span>,<span style=\"background-color: #fff0f0;\">'merchant_long_lat'<\/span>,<span style=\"background-color: #fff0f0;\">\"merchant_suburb\"<\/span>,<span style=\"background-color: #fff0f0;\">\"movement\"<\/span>,<span style=\"background-color: #fff0f0;\">\"gender\"<\/span>]]\r\ndf<span style=\"color: #333333;\">=<\/span>df<span style=\"color: #333333;\">.<\/span>dropna()\r\ndf <span style=\"color: #333333;\">=<\/span> df<span style=\"color: #333333;\">.<\/span>reindex(columns <span style=\"color: #333333;\">=<\/span> df<span style=\"color: #333333;\">.<\/span>columns<span style=\"color: #333333;\">.<\/span>tolist() <span style=\"color: #333333;\">+<\/span> [<span style=\"background-color: #fff0f0;\">'long'<\/span>,<span style=\"background-color: #fff0f0;\">'lat'<\/span>])\r\ndf<span style=\"color: #333333;\">.<\/span>info()\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"784\" height=\"444\" class=\"wp-image-1662\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/taking-relevant-data.jpeg\" alt=\"taking relevant data\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/taking-relevant-data.jpeg 784w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/taking-relevant-data-300x170.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/taking-relevant-data-768x435.jpeg 768w\" sizes=\"auto, (max-width: 784px) 100vw, 784px\" \/><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Extracting the latitude and longitude data<\/span>\r\nlongitude<span style=\"color: #333333;\">=<\/span>[]\r\nlatitude<span style=\"color: #333333;\">=<\/span>[]\r\n<\/pre>\n<\/div>\n<p>for row in df[&#8216;merchant_long_lat&#8217;]:<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">longitude<span style=\"color: #333333;\">.<\/span>append(row<span style=\"color: #333333;\">.<\/span>split(<span style=\"background-color: #fff0f0;\">' '<\/span>)[<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>])\r\nlatitude<span style=\"color: #333333;\">.<\/span>append(row<span style=\"color: #333333;\">.<\/span>split(<span style=\"background-color: #fff0f0;\">' '<\/span>)[<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>])\r\ndf[<span style=\"background-color: #fff0f0;\">\"long\"<\/span>]<span style=\"color: #333333;\">=<\/span>longitude\r\ndf[<span style=\"background-color: #fff0f0;\">\"lat\"<\/span>]<span style=\"color: #333333;\">=<\/span>latitude\r\n<span style=\"color: #888888;\">#Making the values numeric<\/span>\r\ndf[[<span style=\"background-color: #fff0f0;\">\"long\"<\/span>, <span style=\"background-color: #fff0f0;\">\"lat\"<\/span>]] <span style=\"color: #333333;\">=<\/span> df[[<span style=\"background-color: #fff0f0;\">\"long\"<\/span>, <span style=\"background-color: #fff0f0;\">\"lat\"<\/span>]]<span style=\"color: #333333;\">.<\/span>apply(pd<span style=\"color: #333333;\">.<\/span>to_numeric)\r\n<span style=\"color: #888888;\">#The maximum ranges in longitude and latitude<\/span>\r\nranges <span style=\"color: #333333;\">=<\/span> ((df<span style=\"color: #333333;\">.<\/span>long<span style=\"color: #333333;\">.<\/span>min(), df<span style=\"color: #333333;\">.<\/span>long<span style=\"color: #333333;\">.<\/span>max(),\r\ndf<span style=\"color: #333333;\">.<\/span>lat<span style=\"color: #333333;\">.<\/span>min(), df<span style=\"color: #333333;\">.<\/span>lat<span style=\"color: #333333;\">.<\/span>max()))\r\n<span style=\"color: #008800; font-weight: bold;\">print<\/span>(ranges)\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"694\" height=\"59\" class=\"wp-image-1663\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/output-customer-analytics.jpeg\" alt=\"Output (Customer Analytics)\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/output-customer-analytics.jpeg 694w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/output-customer-analytics-300x26.jpeg 300w\" sizes=\"auto, (max-width: 694px) 100vw, 694px\" \/><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Plotting the transactions over the map of australia<\/span>\r\ngeometry <span style=\"color: #333333;\">=<\/span> [Point(xy) <span style=\"color: #008800; font-weight: bold;\">for<\/span> xy <span style=\"color: #000000; font-weight: bold;\">in<\/span> <span style=\"color: #007020;\">zip<\/span>(df[<span style=\"background-color: #fff0f0;\">'long'<\/span>], df[<span style=\"background-color: #fff0f0;\">'lat'<\/span>])]\r\ngdf <span style=\"color: #333333;\">=<\/span> GeoDataFrame(df, geometry<span style=\"color: #333333;\">=<\/span>geometry)\r\n<span style=\"color: #888888;\">#selecting australia<\/span>\r\nworld <span style=\"color: #333333;\">=<\/span> gpd<span style=\"color: #333333;\">.<\/span>read_file(gpd<span style=\"color: #333333;\">.<\/span>datasets<span style=\"color: #333333;\">.<\/span>get_path(<span style=\"background-color: #fff0f0;\">'naturalearth_lowres'<\/span>))\r\naus <span style=\"color: #333333;\">=<\/span> world[world<span style=\"color: #333333;\">.<\/span>name <span style=\"color: #333333;\">==<\/span> <span style=\"background-color: #fff0f0;\">\"Australia\"<\/span>]\r\ngdf<span style=\"color: #333333;\">.<\/span>plot(ax<span style=\"color: #333333;\">=<\/span>aus<span style=\"color: #333333;\">.<\/span>plot(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">12<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">12<\/span>)), marker<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">'o'<\/span>, color<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">'black'<\/span>, markersize<span style=\"color: #333333;\">=<\/span><span style=\"color: #0000dd; font-weight: bold;\">20<\/span>)\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"823\" height=\"672\" class=\"wp-image-1664\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/plotting-the-transactions-over-the-map-of-australi.jpeg\" alt=\"Plotting the transactions over the map of australia\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/plotting-the-transactions-over-the-map-of-australi.jpeg 823w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/plotting-the-transactions-over-the-map-of-australi-300x245.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/plotting-the-transactions-over-the-map-of-australi-768x627.jpeg 768w\" sizes=\"auto, (max-width: 823px) 100vw, 823px\" \/><\/p>\n<p>So the majority of transactions are in the southeast part of Australia, which has the maximum population and the biggest cities. This is clear, as it suggests that transactions will be in places where people live.<\/p>\n<p>Grouping customers by their Mean Balance and Transaction Amount<\/p>\n<p>An important part of customer analytics is customer segmentation. Customers can be segmented and grouped on the basis of a variety of data. The data can be geographic, like latitude and longitude, or it can be demographically based. Demographic data can be age, gender, income, marital status, etc. Customers can be segmented on the basis of behaviours and habits, for example, spending patterns, account balance, things purchased, and so on. Such things help in understanding your customers.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">data_cust<span style=\"color: #333333;\">=<\/span>data[[<span style=\"background-color: #fff0f0;\">\"customer_id\"<\/span>,<span style=\"background-color: #fff0f0;\">\"first_name\"<\/span>,<span style=\"background-color: #fff0f0;\">\"age\"<\/span>,<span style=\"background-color: #fff0f0;\">\"balance\"<\/span>,<span style=\"background-color: #fff0f0;\">'amount'<\/span>]]\r\ncustomer<span style=\"color: #333333;\">=<\/span>data_cust<span style=\"color: #333333;\">.<\/span>groupby([<span style=\"background-color: #fff0f0;\">\"customer_id\"<\/span>,<span style=\"background-color: #fff0f0;\">\"age\"<\/span>,<span style=\"background-color: #fff0f0;\">\"first_name\"<\/span>])[<span style=\"background-color: #fff0f0;\">\"balance\"<\/span>,<span style=\"background-color: #fff0f0;\">\"amount\"<\/span>]<span style=\"color: #333333;\">.<\/span>mean()<span style=\"color: #333333;\">.<\/span>reset_index()\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"606\" height=\"398\" class=\"wp-image-1665\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/grouping-customers-by-their-mean-balance-and-trans.jpeg\" alt=\"Grouping customers by their Mean Balance and Transaction Amount(Customer Analytics)\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/grouping-customers-by-their-mean-balance-and-trans.jpeg 606w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/grouping-customers-by-their-mean-balance-and-trans-300x197.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/grouping-customers-by-their-mean-balance-and-trans-150x100.jpeg 150w\" sizes=\"auto, (max-width: 606px) 100vw, 606px\" \/><\/p>\n<p>The data has now been modelled into a table that contains customer data. The data has the customer id, the customer\u2019s first name, the customer\u2019s age, customer balance, and amount.<\/p>\n<p>We shall be using K-Means clustering to group the customers.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">plt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">16<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>))\r\nsns<span style=\"color: #333333;\">.<\/span>scatterplot(y<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"balance\"<\/span>, x<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"amount\"<\/span>,hue<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"age\"<\/span>, palette<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"Set1\"<\/span>, size<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"age\"<\/span>,sizes<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">50<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">500<\/span>), data<span style=\"color: #333333;\">=<\/span>customer)\r\n<\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1004\" height=\"647\" class=\"wp-image-1666\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/using-k-means-clustering-to-group-the-customers.jpeg\" alt=\"using K-Means clustering to group the customers\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/using-k-means-clustering-to-group-the-customers.jpeg 1004w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/using-k-means-clustering-to-group-the-customers-300x193.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/using-k-means-clustering-to-group-the-customers-768x495.jpeg 768w\" sizes=\"auto, (max-width: 1004px) 100vw, 1004px\" \/><\/p>\n<p>Customer Segmentation- 2D<\/p>\n<p>Now, let us proceed with the segmentation.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#KMeans clustering<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">from<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">sklearn.cluster<\/span> <span style=\"color: #008800; font-weight: bold;\">import<\/span> KMeans\r\nX<span style=\"color: #333333;\">=<\/span>customer[[<span style=\"background-color: #fff0f0;\">\"balance\"<\/span>,<span style=\"background-color: #fff0f0;\">\"amount\"<\/span>]]<span style=\"color: #333333;\">.<\/span>values\r\nwcss<span style=\"color: #333333;\">=<\/span>[]\r\n<span style=\"color: #008800; font-weight: bold;\">for<\/span> i <span style=\"color: #000000; font-weight: bold;\">in<\/span> <span style=\"color: #007020;\">range<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">11<\/span>):\r\nkm<span style=\"color: #333333;\">=<\/span>KMeans(n_clusters<span style=\"color: #333333;\">=<\/span>i)\r\nkm<span style=\"color: #333333;\">.<\/span>fit(X)\r\nwcss<span style=\"color: #333333;\">.<\/span>append(km<span style=\"color: #333333;\">.<\/span>inertia_)\r\n<\/pre>\n<\/div>\n<p>Now, we will use the elbow method to find the optimal number of clusters.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">plt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">12<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">6<\/span>))\r\nplt<span style=\"color: #333333;\">.<\/span>plot(<span style=\"color: #007020;\">range<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">11<\/span>),wcss)\r\nplt<span style=\"color: #333333;\">.<\/span>grid()\r\nplt<span style=\"color: #333333;\">.<\/span>plot(<span style=\"color: #007020;\">range<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">11<\/span>),wcss, linewidth<span style=\"color: #333333;\">=<\/span><span style=\"color: #0000dd; font-weight: bold;\">2<\/span>, color<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"red\"<\/span>, marker <span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"8\"<\/span>)\r\nplt<span style=\"color: #333333;\">.<\/span>xlabel(<span style=\"background-color: #fff0f0;\">\"K Value\"<\/span>)\r\nplt<span style=\"color: #333333;\">.<\/span>xticks(np<span style=\"color: #333333;\">.<\/span>arange(<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">11<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>))\r\nplt<span style=\"color: #333333;\">.<\/span>ylabel(<span style=\"background-color: #fff0f0;\">\"WCSS\"<\/span>)\r\nplt<span style=\"color: #333333;\">.<\/span>show()\r\n<\/pre>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"925\" height=\"516\" class=\"wp-image-1667\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/customer-segmentation-2d.jpeg\" alt=\"Customer Segmentation- 2D \" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/customer-segmentation-2d.jpeg 925w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/customer-segmentation-2d-300x167.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/customer-segmentation-2d-768x428.jpeg 768w\" sizes=\"auto, (max-width: 925px) 100vw, 925px\" \/><\/p>\n<p>Here the X-Axis is the number of groups\/clusters. We will take that many numbers of clusters where the graph is making a turn. So, judging by this graph, we should take the number of clusters= 3.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">km1<span style=\"color: #333333;\">=<\/span>KMeans(n_clusters<span style=\"color: #333333;\">=<\/span><span style=\"color: #0000dd; font-weight: bold;\">3<\/span>)\r\nkm1<span style=\"color: #333333;\">.<\/span>fit(X)\r\ny<span style=\"color: #333333;\">=<\/span>km1<span style=\"color: #333333;\">.<\/span>predict(X)\r\nplt<span style=\"color: #333333;\">.<\/span>figure(figsize<span style=\"color: #333333;\">=<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">16<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>))\r\nplt<span style=\"color: #333333;\">.<\/span>scatter(X[y<span style=\"color: #333333;\">==<\/span><span style=\"color: #0000dd; font-weight: bold;\">0<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>],X[y<span style=\"color: #333333;\">==<\/span><span style=\"color: #0000dd; font-weight: bold;\">0<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>],color<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">'red'<\/span>)\r\nplt<span style=\"color: #333333;\">.<\/span>scatter(X[y<span style=\"color: #333333;\">==<\/span><span style=\"color: #0000dd; font-weight: bold;\">1<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>],X[y<span style=\"color: #333333;\">==<\/span><span style=\"color: #0000dd; font-weight: bold;\">1<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>],color<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">'green'<\/span>)\r\nplt<span style=\"color: #333333;\">.<\/span>scatter(X[y<span style=\"color: #333333;\">==<\/span><span style=\"color: #0000dd; font-weight: bold;\">2<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>],X[y<span style=\"color: #333333;\">==<\/span><span style=\"color: #0000dd; font-weight: bold;\">2<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>],color<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">'blue'<\/span>)\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"990\" height=\"335\" class=\"wp-image-1668\" src=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/taking-number-of-cluster-3-customer-analytics.jpeg\" alt=\"taking number of cluster = 3 (Customer Analytics)\" srcset=\"https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/taking-number-of-cluster-3-customer-analytics.jpeg 990w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/taking-number-of-cluster-3-customer-analytics-300x102.jpeg 300w, https:\/\/mintea.blog\/wp-content\/uploads\/2021\/12\/taking-number-of-cluster-3-customer-analytics-768x260.jpeg 768w\" sizes=\"auto, (max-width: 990px) 100vw, 990px\" \/><\/p>\n<p>There seem to be 3 clusters, the large cluster of maximum people with normal financial resources. The next cluster with better financial resources. The top cluster has only 2 customers with the highest financial resources.<\/p>\n<p>Here, in this dataset, we were able to analyse the customers of this bank in many ways and understand a lot of things, how to analyse data for customer analytics, what is customer analytics and how to proceed with it. Check the code in the link below.<\/p>\n<p><strong>Code:\u00a0<\/strong><a href=\"https:\/\/www.kaggle.com\/prateekmaj21\/customer-analytics-anz-data\" target=\"_blank\" rel=\"noopener\">Here<\/a><\/p>\n<p>Conclusion<\/p>\n<p>Customer Analytics is very important in today\u2019s digital world. Properly implemented analytics helps to predict customers\u2019 reactions to marketing and AD campaigns, their brand adaptation, and their understanding of the customer experience. Other parameters which can be judged are customer satisfaction, customer experiences, marketing campaign success, etc.<\/p>\n<p>So, overall speaking, customer segmentation is a very promising sector and has room for growth and improvement.<\/p>\n<p>Source: analyticsvidhya<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Customer Analytics and Why is it important (with demo by Python) This article was published as a part of the\u00a0Data Science Blogathon Businesses and Companies have a lot of customers these days.\u00a0The number of customers widely vary. It might be in hundreds for a local grocery store, and it may be in millions &hellip; <a href=\"https:\/\/mintea.blog\/?p=1642\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">What is Customer Analytics and Why is it important (with demo by Python)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1666,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[32,63,62,55,56,26,54,64],"class_list":["post-1642","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bookmarked-articles","tag-analytic","tag-clv","tag-crm","tag-customer-analytic","tag-customer-lifecycle","tag-data","tag-data-mining","tag-python"],"_links":{"self":[{"href":"https:\/\/mintea.blog\/index.php?rest_route=\/wp\/v2\/posts\/1642","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mintea.blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mintea.blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mintea.blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mintea.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1642"}],"version-history":[{"count":5,"href":"https:\/\/mintea.blog\/index.php?rest_route=\/wp\/v2\/posts\/1642\/revisions"}],"predecessor-version":[{"id":1729,"href":"https:\/\/mintea.blog\/index.php?rest_route=\/wp\/v2\/posts\/1642\/revisions\/1729"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mintea.blog\/index.php?rest_route=\/wp\/v2\/media\/1666"}],"wp:attachment":[{"href":"https:\/\/mintea.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mintea.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mintea.blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}