{"id":318528,"date":"2021-02-24T15:00:29","date_gmt":"2021-02-24T15:00:29","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=318528"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=318528","title":{"rendered":"\u041f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e RFM-\u0430\u043d\u0430\u043b\u0438\u0437\u0435"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438! \u041e \u0434\u0430\u043d\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043f\u043e \u0434\u0430\u0432\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043a\u0443\u043f\u043e\u043a, \u0447\u0430\u0441\u0442\u043e\u0442\u0435 \u0438 \u0441\u0443\u043c\u043c\u0435 \u0441\u0434\u0435\u043b\u043e\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432. \u041d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 \u0432\u044b \u0431\u0435\u0437 \u0442\u0440\u0443\u0434\u0430 \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0442\u0435\u043e\u0440\u0438\u0438 \u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 rfm-\u0430\u043d\u0430\u043b\u0438\u0437\u0430. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0430 (\u043f\u0440\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445), \u0442\u0430\u043a \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e sql-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u043b\u0438 \u0441\u0438\u043b\u0430\u043c\u0438 \u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a Python\/R. \u041c\u0435\u0442\u043e\u0434\u043e\u043b\u043e\u0433\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043e\u0434\u043d\u0430 \u0438 \u0442\u0430 \u0436\u0435, \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u043d\u043e\u043c\u0435\u0440\u043e\u0432 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u043c \u0438\u043b\u0438 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u044b. \u0412\u0432\u0438\u0434\u0443 \u0432\u0441\u0435\u0433\u043e \u0432\u044b\u0448\u0435\u0438\u0437\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u0440\u0443\u0434\u043d\u043e \u043f\u0440\u0438\u0432\u043d\u0435\u0441\u0442\u0438 \u043d\u043e\u0432\u0438\u0437\u043d\u0443 \u0432 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043b\u0438\u0448\u044c \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0437\u0430\u043e\u0441\u0442\u0440\u0438\u0442\u044c \u0432\u0430\u0448\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 PostgreSQL \u0438 JupyterLab \u0438\u0437 \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0442\u0430 Anaconda. \u0412\u0441\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0432 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 GitHub (<a href=\"https:\/\/github.com\/GrishenkovP\/publications\/tree\/master\/Habr\/rfm_analysis\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0430<\/a>). \u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0432\u0437\u044f\u0442\u044b \u0441 \u043f\u043e\u0440\u0442\u0430\u043b\u0430 Kaggle (<a href=\"https:\/\/www.kaggle.com\/carrie1\/ecommerce-data\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0430<\/a>). <\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u0432 \u0411\u0414 \u0438\u0437\u0443\u0447\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u044b \u0432 \u0438\u0445 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0434\u0435\u043b\u044f\u0442\u044c \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c \u0441 \u0434\u0430\u0442\u0430\u043c\u0438, \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u043c \u0432 \u0437\u0430\u043f\u0438\u0441\u044f\u0445, \u043d\u0435\u0432\u0435\u0440\u043d\u043e\u043c\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u0442\u0438\u043f\u0430 \u043f\u043e\u043b\u0435\u0439. \u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0438\u043b \u0437\u0430\u043f\u0438\u0441\u0438 \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430\u043c\u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u0432. <\/p>\n<pre><code class=\"python\">import pandas as pd import numpy as np import datetime as dt  pd.set_option('display.max_columns', 10) pd.set_option('display.expand_frame_repr', False)  df = pd.read_csv('dataset.csv', sep=',', index_col=[0])  #\u041f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u043a \u043d\u0438\u0436\u043d\u0435\u043c\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443 df.columns = [_.lower() for _ in df.columns.values] #\u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443-\u0434\u0430\u0442\u0443 \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0438 \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 df['invoicedate'] = pd.to_datetime(df['invoicedate'], format='%m\/%d\/%Y %H:%M') df['invoicedate'] = df['invoicedate'].dt.normalize() #\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u043c\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430\u043c\u0438 df_for_report = df.loc[(~df['description'].isnull()) &amp;                        (~df['customerid'].isnull()) &amp;                        (~df['invoiceno'].str.contains('C', case=False))] #\u041d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u043c \u0432\u0441\u0435\u043c \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b convert_dict = {'invoiceno': int, 'customerid': int, 'quantity': int, 'unitprice': float} df_for_report = df_for_report.astype(convert_dict)  #\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 # print(df_for_report.head(3)) # print(df_for_report.dtypes) # print(df_for_report.isnull().sum()) # print(df_for_report.info())  #\u0412\u044b\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0432 \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b \u0444\u043e\u0440\u043c\u0430\u0442\u0430 csv df_for_report.to_csv('dataset_for_report.csv', sep=\";\", index=False)<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u044d\u0442\u0430\u043f\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432 \u0411\u0414 \u043d\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043a\u0430\u043a \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u044b pgAdmin, \u0442\u0430\u043a \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0434\u0430 Python.<\/p>\n<pre><code class=\"python\">import psycopg2  # \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0411\u0414 conn = psycopg2.connect(\"dbname='db' user='postgres' password='gfhjkm' host='localhost' port='5432'\")  print(\"Database opened successfully\")  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u0443\u0440\u0441\u043e\u0440 cursor = conn.cursor()  with conn:     cursor.execute(\"\"\"             DROP TABLE IF EXISTS dataset;         \"\"\")      cursor.execute(\"\"\"             CREATE TABLE IF NOT EXISTS dataset (               invoiceno INTEGER NOT NULL,                stockcode TEXT NOT NULL,               description TEXT NOT NULL,               quantity INTEGER NOT NULL,               invoicedate DATE NOT NULL,               unitprice REAL NOT NULL,               customerid INTEGER NOT NULL,               country TEXT NOT NULL);         \"\"\")   print(\"Operation done successfully\")  # \u0417\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0438 \u043a\u0443\u0440\u0441\u043e\u0440 cursor.close() conn.close() <\/code><\/pre>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u043f\u0440\u043e\u0441\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043d\u0430 \u043d\u0435\u043c \u044f \u043d\u0435 \u0431\u0443\u0434\u0443. \u0415\u0449\u0435 \u0448\u0430\u0433 \u0438 \u043c\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 PostgreSQL. \u042f \u0443\u0436\u0435 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f\u0445, \u0437\u0434\u0435\u0441\u044c \u0441\u043a\u0430\u0436\u0443 \u043b\u0438\u0448\u044c \u0441\u0443\u0442\u044c. \u0414\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0411\u0414 \u043b\u0443\u0447\u0448\u0435 \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0443\u0441\u043b\u0443\u0433 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Pandas.<\/p>\n<pre><code class=\"python\">import psycopg2 from datetime import datetime  start_time = datetime.now()  # \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0411\u0414 conn = psycopg2.connect(\"dbname='db' user='postgres' password='gfhjkm' host='localhost' port='5432'\") print(\"Database opened successfully\")  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u0443\u0440\u0441\u043e\u0440 cursor = conn.cursor()   # \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b. \u0421\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e \u0441 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0432 \u0411\u0414 with open('dataset_for_report.csv', 'r') as f:     next(f)     cursor.copy_from(f, 'dataset',sep=';', columns=('invoiceno', 'stockcode', 'description', 'quantity',                                                     'invoicedate','unitprice', 'customerid', 'country'))     conn.commit()  f.close()  print(\"Operation done successfully\")  # \u0417\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0438 \u043a\u0443\u0440\u0441\u043e\u0440 cursor.close() conn.close()  end_time = datetime.now() print('Duration: {}'.format(end_time - start_time))<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u043f\u043e\u0434\u043e\u0448\u043b\u0430 \u043a \u043a\u043e\u043d\u0446\u0443 \u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e rfm-\u043e\u0442\u0447\u0435\u0442\u0430. \u041a\u0430\u043a \u0432\u044b \u0443\u0436\u0435, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0443\u0441\u043f\u0435\u043b\u0438 \u0434\u043e\u0433\u0430\u0434\u0430\u0442\u044c\u0441\u044f \u0433\u043b\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0440\u043e\u043b\u044c \u0437\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0443\u0442 \u0438\u0433\u0440\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b sql. \u0414\u043b\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0439 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u044f \u0440\u0435\u0448\u0438\u043b \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u043c\u0443 \u0441\u0447\u0435\u0442\u0443 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u043d\u0435\u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0443 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u043e\u0432 \u043d\u0435\u0442 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0431\u043e\u0440\u0430 (\u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b Hadoop \u044f \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0437\u0430 \u0441\u043a\u043e\u0431\u043a\u0430\u043c\u0438 \u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440\u0430). &nbsp;\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f rfm-\u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0442\u0440\u0438 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438: \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u0432\u043d\u043e\u0441\u0442\u0438, \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u0438 \u0441\u0443\u043c\u043c\u044b \u043f\u043e\u043a\u0443\u043f\u043e\u043a.<\/p>\n<p>\u0414\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u044b \u044d\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e. \u0415\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 (\u043f\u0440\u0438\u043c\u0435\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Pandas \u2013 cut \u0438 qcut) \u0438\u043b\u0438 \u0441\u043b\u0435\u043f\u043e \u043f\u0435\u0440\u0435\u043d\u044f\u0442\u044c \u0447\u0443\u0436\u043e\u0439 \u043e\u043f\u044b\u0442. \u041d\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0442\u0430\u043a\u0438\u043c \u043f\u0443\u0442\u0435\u043c \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f. <strong>\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043f\u0440\u0438 \u0443\u0447\u0435\u0442\u0435 \u0441\u0444\u0435\u0440\u044b \u0431\u0438\u0437\u043d\u0435\u0441\u0430, \u0441\u043b\u043e\u0436\u0438\u0432\u0448\u0435\u0439\u0441\u044f \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u043e\u0439 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438, \u0446\u0435\u043b\u0435\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u043a\u043b\u0430\u043c\u043d\u043e-\u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u043e\u0433\u043e \u043c\u0435\u0440\u043e\u043f\u0440\u0438\u044f\u0442\u0438\u044f. &nbsp;<\/strong>\u0415\u0441\u043b\u0438 \u0430\u043a\u0446\u0438\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0442\u0440\u0430\u0442\u043d\u0430\u044f \u0438 \u043e\u0442\u0434\u0435\u043b \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u0430 \u0445\u043e\u0447\u0435\u0442 \u0442\u043e\u0447\u043d\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0430\u0440\u0442\u043d\u0435\u0440\u043e\u0432, \u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043c\u0430\u0441\u0441\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0430\u043a\u0442 \u0441 \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044f\u043c\u0438, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043c\u044b\u0442\u044c \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0432 \u044d\u0442\u043e \u0447\u0438\u0441\u043b\u043e. \u041a\u0430\u043a\u043e\u0439 \u0431\u044b \u0432\u044b \u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u043b\u0438 \u043f\u0443\u0442\u044c, \u0432\u0441\u0435\u0433\u0434\u0430 \u0437\u0430\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0430\u043c\u0438 \u0441\u0435\u0431\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432: \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043b\u0438 \u0437\u0430\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u0432\u0441\u0435\u0445 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0432 \u043d\u0443\u0436\u043d\u044b\u0435 \u0433\u0440\u0443\u043f\u043f\u044b, \u043a\u0430\u043a\u043e\u0432\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0435\u0431\u0435\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0431\u044b\u043b\u044c. \u0412 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u044f \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u043b\u0438\u0448\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u0443\u044e \u0437\u0430\u0433\u043e\u0442\u043e\u0432\u043a\u0443 \u043a\u043e\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0432\u044b \u0443\u0436\u0435 \u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043b\u0438\u0448\u044c \u043d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438. <\/p>\n<pre><code class=\"sql\">--\u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f rfm-\u0430\u043d\u0430\u043b\u0438\u0437\u0430 create function func_recency(days integer) returns integer as $$     select case when days&lt;90 then 1            when (days&gt;=90) and (days&lt;=180) then 2           else 3           end; $$ language sql;  create function func_frequency(transactions integer) returns integer as $$     select case when transactions&gt;50 then 1            when (transactions&gt;=10) and (transactions&lt;=50) then 2           else 3           end; $$ language sql;  create function func_monetary(amount integer) returns integer as $$     select case when amount&gt;10000 then 1            when (amount&gt;=1000) and (amount&lt;=10000) then 2           else 3           end; $$ language sql;<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0440\u0430\u0437\u0431\u043e\u0440\u0443 \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0442\u0440\u043e\u0438\u0442 rfm-\u043e\u0442\u0447\u0435\u0442. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u0434\u0430\u0442\u0430\u043c\u0438. \u0422\u043e\u0447\u043a\u0430 \u043e\u0442\u0441\u0447\u0435\u0442\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e \u0438 \u0437\u0430\u0434\u0430\u043d\u0430 \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b. \u0412\u044b \u0436\u0435 \u0432 \u0441\u0432\u043e\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u043e\u0439\u0442\u0438 \u044d\u0442\u043e\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0438, \u043e\u0442\u043b\u043e\u0432\u0438\u0432 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u0430\u0442\u0443 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0442\u0447\u0435\u0442\u0430, \u0441\u0434\u0432\u0438\u043d\u0443\u0442\u044c\u0441\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0435 \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u043d\u0430\u0437\u0430\u0434. \u0414\u0430\u043b\u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u043f\u043e \u0441\u0443\u0442\u0438, \u0441\u0432\u043e\u0434\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0433\u0434\u0435 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u043e\u043b\u0435 \u043c\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043e\u0439 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0434\u0430\u0442\u043e\u0439 \u043f\u043e\u043a\u0443\u043f\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u0432\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u043b\u0435 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u043f\u043e\u043a\u0443\u043f\u043e\u043a, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u2013 \u0437\u0430 \u043e\u0431\u0449\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u043f\u043e\u043a\u0443\u043f\u043e\u043a \u0437\u0430 \u043f\u0435\u0440\u0438\u043e\u0434. \u0415\u0441\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u044f\u043c \u043d\u0430\u0448\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0438\u0441\u043a\u043e\u043c\u044b\u0439 rfm-\u043e\u0442\u0447\u0435\u0442. \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c sql-\u0441\u043a\u0440\u0438\u043f\u0442 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043a \u043d\u0435\u043c\u0443 \u0438\u0437 BI \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0440\u0430\u0441\u0447\u0435\u0442\u0430\u0445 \u0432 \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0430\u0445 JupyterLab. <\/p>\n<pre><code class=\"sql\">-- rfm-\u0430\u043d\u0430\u043b\u0438\u0437 select d3.*, concat(d3.rfm_recency,d3.rfm_frequency,d3.rfm_monetary) as rfm from  \t(select d2.customerid, \t\t\tdate('2011-11-01')- max(d2.invoicedate) as recency, \t\t\tcast(count(distinct(d2.invoiceno)) as integer) as frequency, \t\t\tcast(sum(d2.amount) as integer) as monetary, \t\t\tfunc_recency(date('2011-11-01')- max(d2.invoicedate)) as rfm_recency, \t\t\tfunc_frequency(cast(count(distinct(d2.invoiceno))as integer)) as rfm_frequency, \t\t\tfunc_monetary(cast(sum(d2.amount)as integer)) as rfm_monetary \tfrom \t    (select d.*, d.quantity * d.unitprice as amount \t     from public.dataset as d  \t     where d.invoicedate &lt; date('2011-11-01')) as d2  \tgroup by d2.customerid \torder by d2.customerid) as d3;<\/code><\/pre>\n<p>\u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u043d\u043e \u044d\u0442\u043e \u043b\u0438\u0448\u044c \u0438\u043b\u043b\u044e\u0437\u0438\u044f. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 rfm-\u0430\u043d\u0430\u043b\u0438\u0437 \u043d\u0435 \u0434\u0430\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0430, \u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u0432 \u0435\u0449\u0435 \u0442\u0430\u0438\u0442 \u043c\u0430\u0441\u0441\u0443 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u043c\u0435\u0442\u0440\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u0448\u0438\u043c \u043a\u043e\u043b\u043b\u0435\u0433\u0430\u043c \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0432\u0435\u0440\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. <\/p>\n<p>\u0427\u0435\u043c \u0435\u0449\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u0442\u0447\u0435\u0442? \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c<strong> \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u0447\u0435\u043a \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430<\/strong>. \u041f\u043e\u0447\u0435\u043c\u0443 \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u0430\u0436\u0435\u043d. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043b\u044e\u0431\u043e\u0435 \u0440\u0435\u043a\u043b\u0430\u043c\u043d\u043e-\u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u043d\u0435\u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u044f \u0432\u0430\u043c \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0442\u0440\u0430\u0442\u044c 50 \u0440\u0443\u0431\u043b\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u0443\u044e \u043f\u043e\u043a\u0443\u043f\u043a\u0443 \u0432 \u043d\u0430\u0448\u0435\u043c \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0435. \u042d\u0442\u043e \u043c\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u043c\u0430\u043b\u043e? \u041e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435 \u043a \u043a\u0430\u043a\u043e\u043c\u0443 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0443 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u044c\u0441\u044f \u044d\u0442\u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442 \u0438 \u0441 \u043a\u0430\u043a\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u044b\u0435 \u043c\u0435\u0440\u043e\u043f\u0440\u0438\u044f\u0442\u0438\u044f.&nbsp; \u041d\u043e \u0442\u0430\u043a\u0436\u0435 \u0432\u0430\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u0434 \u0440\u0443\u043a\u043e\u0439 \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u0447\u0435\u043a, \u043a\u0430\u043a \u043d\u0435\u043a\u0443\u044e \u0446\u0435\u043b\u044c, \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f \u0440\u0435\u043a\u043b\u0430\u043c\u043d\u044b\u0439 \u043e\u0442\u0434\u0435\u043b. \u0415\u0441\u043b\u0438 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u0436\u0434\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044c, \u043f\u0440\u0438\u0448\u0435\u0434\u0448\u0438\u0439 \u0432 \u043c\u0430\u0433\u0430\u0437\u0438\u043d, \u0441\u043e\u0432\u0435\u0440\u0448\u0438\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043d\u0430 5000 \u0440\u0443\u0431\u043b\u0435\u0439, \u0442\u043e \u044d\u0442\u043e \u043e\u0434\u043d\u043e \u0434\u0435\u043b\u043e. \u0415\u0441\u043b\u0438 \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u0447\u0435\u043a \u043d\u0435 \u0432\u044b\u0448\u0435 500 \u0440\u0443\u0431\u043b\u0435\u0439, \u0442\u043e \u044d\u0442\u043e \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0430\u0441\u043a\u043b\u0430\u0434. Sql-\u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e \u043d\u0438\u0436\u0435. \u0414\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u0441\u0447\u0435\u0442\u044b \u0443\u0436\u0435 \u043d\u043e\u0441\u044f\u0442 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0445 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0432 JupyterLab \u0441 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043a \u0411\u0414.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a7c\/db2\/e89\/a7cdb2e89dc382dd35eea253102b4d1b.PNG\" width=\"1366\" height=\"693\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"sql\">-- \u0421\u0443\u043c\u043c\u0430\u0440\u043d\u044b\u0435 \u043f\u0440\u043e\u0434\u0430\u0436\u0438 \u0432 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0435, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u0447\u0435\u043a select r.rfm,  \t   sum(r.monetary) as total_amount, \t   count(r.rfm) as count_customer, \t   cast(avg(r.monetary\/r.frequency) as integer) as avg_check from public.report_rfm_analysis as r  group by r.rfm;<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0435\u0449\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0438\u0437 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c <strong>\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0434\u0430\u0436 \u043f\u043e \u0441\u0442\u0440\u0430\u043d\u0430\u043c \u0432 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u043c \u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438<\/strong>. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442-\u0442\u043e\u0440\u0433\u043e\u0432\u043b\u0438, \u043a\u043e\u0433\u0434\u0430 \u0432 \u043e\u0434\u0438\u043d \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u043b\u044e\u0434\u0438 \u0441\u043e \u0432\u0441\u0435\u0445 \u043a\u043e\u043d\u0446\u043e\u0432 \u0437\u0435\u043c\u043d\u043e\u0433\u043e \u0448\u0430\u0440\u0430.&nbsp; \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0435\u043c\u043e-\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043c\u044b \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u043c, \u0447\u0442\u043e \u0432 \u0440\u044f\u0434\u0435 \u0433\u0440\u0443\u043f\u043f 70% \u043f\u043e\u043a\u0443\u043f\u043e\u043a \u0432 \u0434\u0435\u043d\u0435\u0436\u043d\u043e\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u044e\u0442 \u0436\u0438\u0442\u0435\u043b\u0438 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u044b. \u041d\u0435\u043f\u043b\u043e\u0445\u0430\u044f \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0430 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430\u043c \u043e\u0442\u0434\u0435\u043b\u0430 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u0430.<\/p>\n<pre><code class=\"sql\">-- \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0434\u0430\u0436 \u043f\u043e \u0441\u0442\u0440\u0430\u043d\u0430\u043c \u0432 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u043c \u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 select d2.rfm, \t\td2.country, \t\tcast(sum(d2.amount) as integer) as amount_country, \t\tround(cast(sum(d2.amount)\/sum(sum(d2.amount))over(partition by d2.rfm)*100 as numeric),2) as percent_total_amount from  (select d.*, d.quantity * d.unitprice as amount, r.rfm  \t     from public.dataset as d left join  \t                               public.report_rfm_analysis as r on d.customerid = r.customerid  \t     where d.invoicedate &lt; date('2011-11-01')) as d2 group by d2.rfm, d2.country order by d2.rfm, sum(d2.amount)desc;<\/code><\/pre>\n<p>\u0411\u0443\u0434\u0443\u0449\u0435\u0435 \u0432\u0441\u0435\u0439 \u0442\u043e\u0440\u0433\u043e\u0432\u043b\u0438 \u044d\u0442\u043e \u0441\u0442\u0440\u043e\u0433\u0430\u044f \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0438 \u0440\u0435\u043a\u043b\u0430\u043c\u044b. \u0423 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u043f\u043b\u043e\u0449\u0430\u0434\u043a\u0438 \u0435\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0435\u0433\u043e \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u043a\u0443\u043f\u043a\u0438: \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u0437\u0430 \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0438\u0439 \u0433\u043e\u0434, \u0442\u043e\u043f-7 \u0442\u043e\u0432\u0430\u0440\u043e\u0432, \u0442\u043e\u043f-3 \u0434\u043d\u044f \u0434\u043b\u044f \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u043a\u0443\u043f\u043e\u043a, \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u0447\u0435\u043a \u0438 \u0442. \u0434. \u041d\u043e \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0439 \u044d\u0442\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0441\u0442\u044b\u043a\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0434\u0435\u0439 \u0438 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c\u044b\u0435 \u0430\u043a\u0446\u0438\u0438 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439, \u0447\u0442\u043e \u0437\u0430 \u0432\u0441\u044e \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u0431\u0438\u0437\u043d\u0435\u0441-\u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0439 \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u043e\u043a\u0443\u043f\u0430\u043b \u0432 \u0432\u0430\u0448\u0435\u043c \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u044b\u0440, \u0430 \u0432\u044b \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0448\u043b\u0435\u0442\u0435 \u0435\u043c\u0443 \u0441\u043c\u0441-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e \u0441\u043a\u0438\u0434\u043a\u0430\u0445 \u043d\u0430 \u0448\u043e\u043a\u043e\u043b\u0430\u0434, \u0431\u0430\u043d\u0430\u043d\u044b, \u043e\u0445\u043b\u0430\u0436\u0434\u0435\u043d\u043d\u0443\u044e \u043a\u0443\u0440\u0438\u0446\u0443. \u0412 \u043d\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0443\u0436\u0435 \u0432\u0440\u044f\u0434 \u043b\u0438 \u043e\u0446\u0435\u043d\u044f\u0442 \u0442\u0430\u043a\u0443\u044e \u0437\u0430\u0431\u043e\u0442\u0443 \u043e \u0441\u0432\u043e\u0435\u043c \u043a\u043e\u0448\u0435\u043b\u043a\u0435 \u0438 \u0441\u043a\u043e\u0440\u0435\u0435 \u043e\u0442\u043d\u0435\u0441\u0443\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043a \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u0441\u043f\u0430\u043c\u0430. <strong>\u0415\u0441\u043b\u0438 \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u044f \u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u2013 \u0442\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0446\u0435\u043b\u0435\u0432\u0430\u044f. <\/strong>\u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0440\u0430\u0441\u0447\u0435\u0442 <strong>\u0442\u043e\u043f-3 \u0434\u043d\u044f \u043f\u043e \u043e\u0431\u044a\u0435\u043c\u0443 \u043f\u0440\u043e\u0434\u0430\u0436 \u0432 \u0440\u0430\u0437\u0440\u0435\u0437\u0435 \u0441\u0435\u0433\u043c\u0435\u043d\u0442-\u0441\u0442\u0440\u0430\u043d\u0430.<\/strong><\/p>\n<pre><code class=\"sql\">-- \u041d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043d\u044f \u043c\u0435\u0441\u044f\u0446\u0430 create function func_day_of_week(number_day integer) returns text as $$ select (string_to_array('sunday,monday,tuesday,wednesday,thursday,friday,saturday',','))[number_day]; $$ language sql;  -- \u0422\u043e\u043f-3 \u0434\u043d\u044f \u043f\u043e \u043e\u0431\u044a\u0435\u043c\u0443 \u043f\u0440\u043e\u0434\u0430\u0436 \u0432 \u0440\u0430\u0437\u0440\u0435\u0437\u0435 \u0441\u0435\u0433\u043c\u0435\u043d\u0442-\u0441\u0442\u0440\u0430\u043d\u0430 select d4.rfm, d4.country, max(d4.top) as top_3_days from  \t  (select d3.rfm, d3.country, string_agg(d3.day_of_week,', ')over(partition by d3.rfm, d3.country) as top \t   from  \t\t(select d2.rfm, d2.country, d2.day_of_week,sum(d2.amount) as total_amount, \t\t     row_number ()over(partition by d2.rfm, d2.country order by d2.rfm, d2.country, sum(d2.amount)desc) \t\tfrom  \t\t     (select r.rfm,  \t\t             d.country,\t              \t\t             func_day_of_week(cast(to_char(d.invoicedate, 'D') as integer)) as day_of_week, \t\t             d.quantity * d.unitprice as amount \t\t      from public.dataset as d left join public.report_rfm_analysis as r on d.customerid = r.customerid \t\t      where d.invoicedate &lt; date('2011-11-01')) as d2 \t\tgroup by d2.rfm, d2.country, d2.day_of_week \t\torder by d2.rfm, d2.country, sum(d2.amount) desc) as d3 \t  where d3.row_number &lt;= 3) as d4 group by d4.rfm, d4.country<\/code><\/pre>\n<p><strong><em>\u041a\u0440\u0430\u0442\u043a\u0438\u0435 \u0432\u044b\u0432\u043e\u0434\u044b<\/em><\/strong><em>. RFM-\u0430\u043d\u0430\u043b\u0438\u0437 \u0438 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u0441\u0447\u0435\u0442\u044b \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u0443\u0442\u0435\u043c \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f sql \u0438 \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u043e\u0432 Python. \u041f\u0440\u0438 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0432\u0430\u0436\u043d\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0444\u0435\u0440\u0443 \u0431\u0438\u0437\u043d\u0435\u0441\u0430, \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u0443\u044e \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443 \u0438 \u0446\u0435\u043b\u0438 \u0440\u0435\u043a\u043b\u0430\u043c\u043d\u043e\u0439 \u0430\u043a\u0446\u0438\u0438. RFM-\u043e\u0442\u0447\u0435\u0442 \u043d\u0435 \u0434\u0430\u0435\u0442 \u0432\u0441\u0435\u0439 \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0442\u044c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0440\u0430\u0441\u0447\u0435\u0442\u0430\u043c\u0438.<\/em><\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435. \u0412\u0441\u0435\u043c \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u044f, \u0443\u0434\u0430\u0447\u0438 \u0438 \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u043f\u0435\u0445\u043e\u0432!<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/543950\/\"> https:\/\/habr.com\/ru\/post\/543950\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438! \u041e \u0434\u0430\u043d\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043f\u043e \u0434\u0430\u0432\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043a\u0443\u043f\u043e\u043a, \u0447\u0430\u0441\u0442\u043e\u0442\u0435 \u0438 \u0441\u0443\u043c\u043c\u0435 \u0441\u0434\u0435\u043b\u043e\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432. \u041d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 \u0432\u044b \u0431\u0435\u0437 \u0442\u0440\u0443\u0434\u0430 \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0442\u0435\u043e\u0440\u0438\u0438 \u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 rfm-\u0430\u043d\u0430\u043b\u0438\u0437\u0430. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0430 (\u043f\u0440\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445), \u0442\u0430\u043a \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e sql-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u043b\u0438 \u0441\u0438\u043b\u0430\u043c\u0438 \u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a Python\/R. \u041c\u0435\u0442\u043e\u0434\u043e\u043b\u043e\u0433\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043e\u0434\u043d\u0430 \u0438 \u0442\u0430 \u0436\u0435, \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u043d\u043e\u043c\u0435\u0440\u043e\u0432 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u043c \u0438\u043b\u0438 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u044b. \u0412\u0432\u0438\u0434\u0443 \u0432\u0441\u0435\u0433\u043e \u0432\u044b\u0448\u0435\u0438\u0437\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u0440\u0443\u0434\u043d\u043e \u043f\u0440\u0438\u0432\u043d\u0435\u0441\u0442\u0438 \u043d\u043e\u0432\u0438\u0437\u043d\u0443 \u0432 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043b\u0438\u0448\u044c \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0437\u0430\u043e\u0441\u0442\u0440\u0438\u0442\u044c \u0432\u0430\u0448\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 PostgreSQL \u0438 JupyterLab \u0438\u0437 \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0442\u0430 Anaconda. \u0412\u0441\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0432 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 GitHub (<a href=\"https:\/\/github.com\/GrishenkovP\/publications\/tree\/master\/Habr\/rfm_analysis\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0430<\/a>). \u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0432\u0437\u044f\u0442\u044b \u0441 \u043f\u043e\u0440\u0442\u0430\u043b\u0430 Kaggle (<a href=\"https:\/\/www.kaggle.com\/carrie1\/ecommerce-data\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0430<\/a>). <\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u0432 \u0411\u0414 \u0438\u0437\u0443\u0447\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u044b \u0432 \u0438\u0445 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0434\u0435\u043b\u044f\u0442\u044c \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c \u0441 \u0434\u0430\u0442\u0430\u043c\u0438, \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u043c \u0432 \u0437\u0430\u043f\u0438\u0441\u044f\u0445, \u043d\u0435\u0432\u0435\u0440\u043d\u043e\u043c\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u0442\u0438\u043f\u0430 \u043f\u043e\u043b\u0435\u0439. \u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0438\u043b \u0437\u0430\u043f\u0438\u0441\u0438 \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430\u043c\u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u0432. <\/p>\n<pre><code class=\"python\">import pandas as pd import numpy as np import datetime as dt  pd.set_option('display.max_columns', 10) pd.set_option('display.expand_frame_repr', False)  df = pd.read_csv('dataset.csv', sep=',', index_col=[0])  #\u041f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u043a \u043d\u0438\u0436\u043d\u0435\u043c\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443 df.columns = [_.lower() for _ in df.columns.values] #\u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443-\u0434\u0430\u0442\u0443 \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0438 \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 df['invoicedate'] = pd.to_datetime(df['invoicedate'], format='%m\/%d\/%Y %H:%M') df['invoicedate'] = df['invoicedate'].dt.normalize() #\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u043c\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430\u043c\u0438 df_for_report = df.loc[(~df['description'].isnull()) &amp;                        (~df['customerid'].isnull()) &amp;                        (~df['invoiceno'].str.contains('C', case=False))] #\u041d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u043c \u0432\u0441\u0435\u043c \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b convert_dict = {'invoiceno': int, 'customerid': int, 'quantity': int, 'unitprice': float} df_for_report = df_for_report.astype(convert_dict)  #\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 # print(df_for_report.head(3)) # print(df_for_report.dtypes) # print(df_for_report.isnull().sum()) # print(df_for_report.info())  #\u0412\u044b\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0432 \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b \u0444\u043e\u0440\u043c\u0430\u0442\u0430 csv df_for_report.to_csv('dataset_for_report.csv', sep=\";\", index=False)<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u044d\u0442\u0430\u043f\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432 \u0411\u0414 \u043d\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043a\u0430\u043a \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u044b pgAdmin, \u0442\u0430\u043a \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0434\u0430 Python.<\/p>\n<pre><code class=\"python\">import psycopg2  # \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0411\u0414 conn = psycopg2.connect(\"dbname='db' user='postgres' password='gfhjkm' host='localhost' port='5432'\")  print(\"Database opened successfully\")  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u0443\u0440\u0441\u043e\u0440 cursor = conn.cursor()  with conn:     cursor.execute(\"\"\"             DROP TABLE IF EXISTS dataset;         \"\"\")      cursor.execute(\"\"\"             CREATE TABLE IF NOT EXISTS dataset (               invoiceno INTEGER NOT NULL,                stockcode TEXT NOT NULL,               description TEXT NOT NULL,               quantity INTEGER NOT NULL,               invoicedate DATE NOT NULL,               unitprice REAL NOT NULL,               customerid INTEGER NOT NULL,               country TEXT NOT NULL);         \"\"\")   print(\"Operation done successfully\")  # \u0417\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0438 \u043a\u0443\u0440\u0441\u043e\u0440 cursor.close() conn.close() <\/code><\/pre>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u043f\u0440\u043e\u0441\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043d\u0430 \u043d\u0435\u043c \u044f \u043d\u0435 \u0431\u0443\u0434\u0443. \u0415\u0449\u0435 \u0448\u0430\u0433 \u0438 \u043c\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 PostgreSQL. \u042f \u0443\u0436\u0435 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f\u0445, \u0437\u0434\u0435\u0441\u044c \u0441\u043a\u0430\u0436\u0443 \u043b\u0438\u0448\u044c \u0441\u0443\u0442\u044c. \u0414\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0411\u0414 \u043b\u0443\u0447\u0448\u0435 \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0443\u0441\u043b\u0443\u0433 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Pandas.<\/p>\n<pre><code class=\"python\">import psycopg2 from datetime import datetime  start_time = datetime.now()  # \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0411\u0414 conn = psycopg2.connect(\"dbname='db' user='postgres' password='gfhjkm' host='localhost' port='5432'\") print(\"Database opened successfully\")  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u0443\u0440\u0441\u043e\u0440 cursor = conn.cursor()   # \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b. \u0421\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e \u0441 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0432 \u0411\u0414 with open('dataset_for_report.csv', 'r') as f:     next(f)     cursor.copy_from(f, 'dataset',sep=';', columns=('invoiceno', 'stockcode', 'description', 'quantity',                                                     'invoicedate','unitprice', 'customerid', 'country'))     conn.commit()  f.close()  print(\"Operation done successfully\")  # \u0417\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0438 \u043a\u0443\u0440\u0441\u043e\u0440 cursor.close() conn.close()  end_time = datetime.now() print('Duration: {}'.format(end_time - start_time))<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u043f\u043e\u0434\u043e\u0448\u043b\u0430 \u043a \u043a\u043e\u043d\u0446\u0443 \u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e rfm-\u043e\u0442\u0447\u0435\u0442\u0430. \u041a\u0430\u043a \u0432\u044b \u0443\u0436\u0435, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0443\u0441\u043f\u0435\u043b\u0438 \u0434\u043e\u0433\u0430\u0434\u0430\u0442\u044c\u0441\u044f \u0433\u043b\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0440\u043e\u043b\u044c \u0437\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0443\u0442 \u0438\u0433\u0440\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b sql. \u0414\u043b\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0439 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u044f \u0440\u0435\u0448\u0438\u043b \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u043c\u0443 \u0441\u0447\u0435\u0442\u0443 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u043d\u0435\u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0443 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u043e\u0432 \u043d\u0435\u0442 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0431\u043e\u0440\u0430 (\u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b Hadoop \u044f \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0437\u0430 \u0441\u043a\u043e\u0431\u043a\u0430\u043c\u0438 \u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440\u0430). &nbsp;\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f rfm-\u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0442\u0440\u0438 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438: \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u0432\u043d\u043e\u0441\u0442\u0438, \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u0438 \u0441\u0443\u043c\u043c\u044b \u043f\u043e\u043a\u0443\u043f\u043e\u043a.<\/p>\n<p>\u0414\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u044b \u044d\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e. \u0415\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 (\u043f\u0440\u0438\u043c\u0435\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Pandas \u2013 cut \u0438 qcut) \u0438\u043b\u0438 \u0441\u043b\u0435\u043f\u043e \u043f\u0435\u0440\u0435\u043d\u044f\u0442\u044c \u0447\u0443\u0436\u043e\u0439 \u043e\u043f\u044b\u0442. \u041d\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0442\u0430\u043a\u0438\u043c \u043f\u0443\u0442\u0435\u043c \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f. <strong>\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043f\u0440\u0438 \u0443\u0447\u0435\u0442\u0435 \u0441\u0444\u0435\u0440\u044b \u0431\u0438\u0437\u043d\u0435\u0441\u0430, \u0441\u043b\u043e\u0436\u0438\u0432\u0448\u0435\u0439\u0441\u044f \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u043e\u0439 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438, \u0446\u0435\u043b\u0435\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u043a\u043b\u0430\u043c\u043d\u043e-\u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u043e\u0433\u043e \u043c\u0435\u0440\u043e\u043f\u0440\u0438\u044f\u0442\u0438\u044f. &nbsp;<\/strong>\u0415\u0441\u043b\u0438 \u0430\u043a\u0446\u0438\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0442\u0440\u0430\u0442\u043d\u0430\u044f \u0438 \u043e\u0442\u0434\u0435\u043b \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u0430 \u0445\u043e\u0447\u0435\u0442 \u0442\u043e\u0447\u043d\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0430\u0440\u0442\u043d\u0435\u0440\u043e\u0432, \u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043c\u0430\u0441\u0441\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0430\u043a\u0442 \u0441 \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044f\u043c\u0438, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043c\u044b\u0442\u044c \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0432 \u044d\u0442\u043e \u0447\u0438\u0441\u043b\u043e. \u041a\u0430\u043a\u043e\u0439 \u0431\u044b \u0432\u044b \u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u043b\u0438 \u043f\u0443\u0442\u044c, \u0432\u0441\u0435\u0433\u0434\u0430 \u0437\u0430\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0430\u043c\u0438 \u0441\u0435\u0431\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432: \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043b\u0438 \u0437\u0430\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u0432\u0441\u0435\u0445 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0432 \u043d\u0443\u0436\u043d\u044b\u0435 \u0433\u0440\u0443\u043f\u043f\u044b, \u043a\u0430\u043a\u043e\u0432\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0435\u0431\u0435\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0431\u044b\u043b\u044c. \u0412 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u044f \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u043b\u0438\u0448\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u0443\u044e \u0437\u0430\u0433\u043e\u0442\u043e\u0432\u043a\u0443 \u043a\u043e\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0432\u044b \u0443\u0436\u0435 \u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043b\u0438\u0448\u044c \u043d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438. <\/p>\n<pre><code class=\"sql\">--\u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f rfm-\u0430\u043d\u0430\u043b\u0438\u0437\u0430 create function func_recency(days integer) returns integer as $$     select case when days&lt;90 then 1            when (days&gt;=90) and (days&lt;=180) then 2           else 3           end; $$ language sql;  create function func_frequency(transactions integer) returns integer as $$     select case when transactions&gt;50 then 1            when (transactions&gt;=10) and (transactions&lt;=50) then 2           else 3           end; $$ language sql;  create function func_monetary(amount integer) returns integer as $$     select case when amount&gt;10000 then 1            when (amount&gt;=1000) and (amount&lt;=10000) then 2           else 3           end; $$ language sql;<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0440\u0430\u0437\u0431\u043e\u0440\u0443 \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0442\u0440\u043e\u0438\u0442 rfm-\u043e\u0442\u0447\u0435\u0442. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u0434\u0430\u0442\u0430\u043c\u0438. \u0422\u043e\u0447\u043a\u0430 \u043e\u0442\u0441\u0447\u0435\u0442\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e \u0438 \u0437\u0430\u0434\u0430\u043d\u0430 \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b. \u0412\u044b \u0436\u0435 \u0432 \u0441\u0432\u043e\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u043e\u0439\u0442\u0438 \u044d\u0442\u043e\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0438, \u043e\u0442\u043b\u043e\u0432\u0438\u0432 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u0430\u0442\u0443 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0442\u0447\u0435\u0442\u0430, \u0441\u0434\u0432\u0438\u043d\u0443\u0442\u044c\u0441\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0435 \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u043d\u0430\u0437\u0430\u0434. \u0414\u0430\u043b\u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u043f\u043e \u0441\u0443\u0442\u0438, \u0441\u0432\u043e\u0434\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0433\u0434\u0435 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u043e\u043b\u0435 \u043c\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043e\u0439 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0434\u0430\u0442\u043e\u0439 \u043f\u043e\u043a\u0443\u043f\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u0432\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u043b\u0435 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u043f\u043e\u043a\u0443\u043f\u043e\u043a, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u2013 \u0437\u0430 \u043e\u0431\u0449\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u043f\u043e\u043a\u0443\u043f\u043e\u043a \u0437\u0430 \u043f\u0435\u0440\u0438\u043e\u0434. \u0415\u0441\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u044f\u043c \u043d\u0430\u0448\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0438\u0441\u043a\u043e\u043c\u044b\u0439 rfm-\u043e\u0442\u0447\u0435\u0442. \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c sql-\u0441\u043a\u0440\u0438\u043f\u0442 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043a \u043d\u0435\u043c\u0443 \u0438\u0437 BI \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0440\u0430\u0441\u0447\u0435\u0442\u0430\u0445 \u0432 \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0430\u0445 JupyterLab. <\/p>\n<pre><code class=\"sql\">-- rfm-\u0430\u043d\u0430\u043b\u0438\u0437 select d3.*, concat(d3.rfm_recency,d3.rfm_frequency,d3.rfm_monetary) as rfm from  \t(select d2.customerid, \t\t\tdate('2011-11-01')- max(d2.invoicedate) as recency, \t\t\tcast(count(distinct(d2.invoiceno)) as integer) as frequency, \t\t\tcast(sum(d2.amount) as integer) as monetary, \t\t\tfunc_recency(date('2011-11-01')- max(d2.invoicedate)) as rfm_recency, \t\t\tfunc_frequency(cast(count(distinct(d2.invoiceno))as integer)) as rfm_frequency, \t\t\tfunc_monetary(cast(sum(d2.amount)as integer)) as rfm_monetary \tfrom \t    (select d.*, d.quantity * d.unitprice as amount \t     from public.dataset as d  \t     where d.invoicedate &lt; date('2011-11-01')) as d2  \tgroup by d2.customerid \torder by d2.customerid) as d3;<\/code><\/pre>\n<p>\u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u043d\u043e \u044d\u0442\u043e \u043b\u0438\u0448\u044c \u0438\u043b\u043b\u044e\u0437\u0438\u044f. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 rfm-\u0430\u043d\u0430\u043b\u0438\u0437 \u043d\u0435 \u0434\u0430\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0430, \u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u0432 \u0435\u0449\u0435 \u0442\u0430\u0438\u0442 \u043c\u0430\u0441\u0441\u0443 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u043c\u0435\u0442\u0440\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u0448\u0438\u043c \u043a\u043e\u043b\u043b\u0435\u0433\u0430\u043c \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0432\u0435\u0440\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. <\/p>\n<p>\u0427\u0435\u043c \u0435\u0449\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u0442\u0447\u0435\u0442? \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c<strong> \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u0447\u0435\u043a \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430<\/strong>. \u041f\u043e\u0447\u0435\u043c\u0443 \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u0430\u0436\u0435\u043d. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043b\u044e\u0431\u043e\u0435 \u0440\u0435\u043a\u043b\u0430\u043c\u043d\u043e-\u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u043d\u0435\u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u044f \u0432\u0430\u043c \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0442\u0440\u0430\u0442\u044c 50 \u0440\u0443\u0431\u043b\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u0443\u044e \u043f\u043e\u043a\u0443\u043f\u043a\u0443 \u0432 \u043d\u0430\u0448\u0435\u043c \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0435. \u042d\u0442\u043e \u043c\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u043c\u0430\u043b\u043e? \u041e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435 \u043a \u043a\u0430\u043a\u043e\u043c\u0443 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0443 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u044c\u0441\u044f \u044d\u0442\u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442 \u0438 \u0441 \u043a\u0430\u043a\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u044b\u0435 \u043c\u0435\u0440\u043e\u043f\u0440\u0438\u044f\u0442\u0438\u044f.&nbsp; \u041d\u043e \u0442\u0430\u043a\u0436\u0435 \u0432\u0430\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u0434 \u0440\u0443\u043a\u043e\u0439 \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u0447\u0435\u043a, \u043a\u0430\u043a \u043d\u0435\u043a\u0443\u044e \u0446\u0435\u043b\u044c, \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f \u0440\u0435\u043a\u043b\u0430\u043c\u043d\u044b\u0439 \u043e\u0442\u0434\u0435\u043b. \u0415\u0441\u043b\u0438 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u0436\u0434\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044c, \u043f\u0440\u0438\u0448\u0435\u0434\u0448\u0438\u0439 \u0432 \u043c\u0430\u0433\u0430\u0437\u0438\u043d, \u0441\u043e\u0432\u0435\u0440\u0448\u0438\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043d\u0430 5000 \u0440\u0443\u0431\u043b\u0435\u0439, \u0442\u043e \u044d\u0442\u043e \u043e\u0434\u043d\u043e \u0434\u0435\u043b\u043e. \u0415\u0441\u043b\u0438 \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u0447\u0435\u043a \u043d\u0435 \u0432\u044b\u0448\u0435 500 \u0440\u0443\u0431\u043b\u0435\u0439, \u0442\u043e \u044d\u0442\u043e \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0430\u0441\u043a\u043b\u0430\u0434. Sql-\u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e \u043d\u0438\u0436\u0435. \u0414\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u0441\u0447\u0435\u0442\u044b \u0443\u0436\u0435 \u043d\u043e\u0441\u044f\u0442 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0445 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0432 JupyterLab \u0441 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043a \u0411\u0414.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"sql\">-- \u0421\u0443\u043c\u043c\u0430\u0440\u043d\u044b\u0435 \u043f\u0440\u043e\u0434\u0430\u0436\u0438 \u0432<\/code><\/pre>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-318528","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/318528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=318528"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/318528\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=318528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=318528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=318528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}