{"id":389930,"date":"2024-06-29T08:55:38","date_gmt":"2024-06-29T08:55:38","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=389930"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=389930","title":{"rendered":"<span>Pyspark. \u0410\u043d\u0430\u043b\u0438\u0437 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0433\u0434\u0430 Pandas \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/v7\/cp\/i2\/v7cpi2sq0googz11-senuvd6nt0.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/v7\/cp\/i2\/v7cpi2sq0googz11-senuvd6nt0.png\"\/><figcaption><\/figcaption><\/figure>\n<\/th>\n<th>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ry\/iu\/d9\/ryiud95vu_azq2winu02w5sdb5i.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/ry\/iu\/d9\/ryiud95vu_azq2winu02w5sdb5i.png\"\/><figcaption><\/figcaption><\/figure>\n<\/th>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Pandas &#8212; \u043e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a Python \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0430\u043c \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0440\u0430\u0441\u0442\u0443\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0418 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430\u0441\u0442\u0443\u043f\u0438\u0442 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0441\u0442\u0430\u043d\u0435\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a PySpark \u0432\u044b\u0440\u0443\u0447\u0430\u0435\u0442 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0438 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041d\u0443 \u0447\u0442\u043e \u0436\u0435, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043a\u0430\u0447\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043d\u0430\u0431\u043e\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 kaggle. \u0418\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 colab \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0441 kaggle \u043d\u0438\u0436\u0435:<\/p>\n<ol>\n<li>\n<p>\u0417\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u0440\u0430\u0437\u0434\u0435\u043b Account \u043d\u0430 <a href=\"http:\/\/kaggle.com\" rel=\"noopener noreferrer nofollow\">kaggle.com<\/a><\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u043b\u0438\u0441\u0442\u044b\u0432\u0430\u0435\u043c \u0432\u043d\u0438\u0437 \u0434\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u0430 API<\/p>\n<\/li>\n<li>\n<p>\u0416\u043c\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0443 Create New API Token, \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b kaggle.json<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043b\u0435\u0435 \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0432 Files \u043d\u0430 Google Colab, \u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u0430\u0436\u0434\u044b\u0435 12 \u0447\u0430\u0441\u043e\u0432 \u0441\u0435\u0441\u0441\u0438\u044f Google Colab \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f, \u0442\u043e \u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e Colab Notebooks \u043d\u0430 Google Drive<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/800\/e54\/b1d\/800e54b1d3aa6c3a39b5309fb5839ab3.png\" width=\"956\" height=\"482\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/800\/e54\/b1d\/800e54b1d3aa6c3a39b5309fb5839ab3.png\"\/><figcaption><\/figcaption><\/figure>\n<blockquote>\n<p>(<a href=\"https:\/\/www.kaggle.com\/general\/74235\" rel=\"noopener noreferrer nofollow\">https:\/\/www.kaggle.com\/general\/74235<\/a>) &#8212; \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435<\/p>\n<\/blockquote>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u043e\u043c <a href=\"https:\/\/www.kaggle.com\/c\/riiid-test-answer-prediction\" rel=\"noopener noreferrer nofollow\">Riiid Answer Correctness Prediction<\/a><\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/un\/gl\/pa\/unglpaikmyh-efzkqq6ritxypge.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/un\/gl\/pa\/unglpaikmyh-efzkqq6ritxypge.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u043e\u0434 \u043d\u0438\u0436\u0435 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0434\u0430\u0442\u0430\u0441\u0435\u0442, \u0432\u0441\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043b\u0435\u0436\u0430\u0442 \u0432 \u043f\u0430\u043f\u043a\u0435 data.<\/p>\n<pre><code class=\"python\"> ! pip install -q kaggle from google.colab import drive drive.mount('\/content\/drive') ! mkdir ~\/.kaggle ! cp '\/content\/drive\/MyDrive\/Colab Notebooks\/kaggle.json' ~\/.kaggle\/ # \u0444\u0430\u0439\u043b kaggle.json \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0432 \u043b\u044e\u0431\u0443\u044e \u043f\u0430\u043f\u043a\u0443 \u0432 Drive, \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b cp ! chmod 600 ~\/.kaggle\/kaggle.json ! kaggle competitions download -c 'riiid-test-answer-prediction' ! mkdir data ! unzip riiid-test-answer-prediction.zip -d data <\/code><\/pre>\n<p>\u0414\u0430\u0442\u0430\u0441\u0435\u0442, \u0441\u043a\u0430\u0436\u0435\u043c \u0442\u0430\u043a, \u043d\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439, \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0432\u0430\u0448\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u044b \u0432\u043f\u043e\u043b\u043d\u0435 \u0445\u0432\u0430\u0442\u0438\u0442 \u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 pandas. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0431\u0443\u0434\u0443 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Google Colab. \u0412 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 12 \u0413\u0411 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0443\u0447\u0435\u0431\u043d\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f \u044d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 pandas.<\/p>\n<h3>1. Pandas<\/h3>\n<pre><code class=\"python\">import pandas as pd  df_train = pd.read_csv('data\/train.csv',                         dtype={'content_id': 'int16',                                'content_type_id': 'int8',                                'task_container_id': 'int16',                                'user_answer': 'int8',                                'answered_correctly': 'int8',                                'prior_question_elapsed_time': 'float32'}) <\/code><\/pre>\n<p>\u0412\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<pre><code class=\"python\">df_train.head() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ba\/gp\/pt\/bagpptke3lzzcdjqx8y-hxgenmc.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/ba\/gp\/pt\/bagpptke3lzzcdjqx8y-hxgenmc.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">df_train.info() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/g7\/7u\/hz\/g77uhzrv2nprfdtq3uu7hlywzme.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/g7\/7u\/hz\/g77uhzrv2nprfdtq3uu7hlywzme.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 4 \u0413\u0411 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u0447\u0442\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0440\u0435\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u0438, \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 colab \u0434\u043b\u044f \u043d\u0430\u0441.<\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u0443\u0441\u0442\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"python\">df_train.isna().sum() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/vd\/gl\/rj\/vdglrja62erzeagv34hyinhnnfq.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/vd\/gl\/rj\/vdglrja62erzeagv34hyinhnnfq.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">df_train[['prior_question_elapsed_time', 'prior_question_had_explanation']].isna().mean() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/37\/9w\/uz\/379wuzhixhktxkkzl96xcb9pa2u.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/37\/9w\/uz\/379wuzhixhktxkkzl96xcb9pa2u.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418\u043c\u0435\u0435\u043c: \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 prior_question_elapsed_time \u0432\u0441\u0435\u0433\u043e \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 2% \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432, \u0432 prior_question_had_explanation \u0438 \u0442\u043e\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0435. \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u043c dropna \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 pandas \u0438&#8230;<\/p>\n<pre><code class=\"python\">df = df_train.dropna() <\/code><\/pre>\n<p>&#8230; \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ji\/mk\/_s\/jimk_sgwsng0jnr45bd7yqkty5e.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/ji\/mk\/_s\/jimk_sgwsng0jnr45bd7yqkty5e.png\"\/><figcaption><\/figcaption><\/figure>\n<blockquote>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435, \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 read_csv \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0422\u043e\u0433\u0434\u0430 pandas \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043b \u0431\u044b \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443 \u0441 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043b\u0438\u0431\u043e \u0442\u0438\u043f int64, \u043b\u0438\u0431\u043e \u0442\u0438\u043f float64. \u0410 \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u043d\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u043d\u0435\u043c\u0430\u043b\u043e&#8230;<\/p>\n<\/blockquote>\n<p>\u0422\u0430\u043c, \u0433\u0434\u0435 \u043d\u0435 \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0441\u044f pandas, \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0435\u043c \u043a \u043f\u043e\u043c\u043e\u0449\u0438 pyspark.<\/p>\n<h3>2. Pyspark<\/h3>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c pyspark \u0438 pyarrow. Pyarrow \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 pyspark, \u0447\u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f<\/p>\n<pre><code>! pip install pyspark ! pip install pyarrow <\/code><\/pre>\n<pre><code class=\"python\">from pyspark.sql import SparkSession import os os.environ[\"PYARROW_IGNORE_TIMEZONE\"] = \"1\" # \u0431\u0435\u0437 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 \u0441 \u043f\u0440\u043e\u0441\u044c\u0431\u043e\u0439 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 1, \u0447\u0442\u043e \u043c\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0438 \u0434\u0435\u043b\u0430\u0435\u043c   spark = SparkSession.builder.getOrCreate() spark.conf.set(\"spark.sql.execution.arrow.pyspark.enabled\", \"true\") spark <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/v5\/4p\/k6\/v54pk67pvvy5cqht3syia5jn8_g.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/v5\/4p\/k6\/v54pk67pvvy5cqht3syia5jn8_g.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0447\u0442\u0435\u043c \u043d\u0430\u0448 \u0444\u0430\u0439\u043b \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u0415\u0441\u043b\u0438 \u043c\u044b \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0434\u0438\u043d \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 inferSchema=True, pyspark \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442 \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438.<\/p>\n<pre><code class=\"python\">df = spark.read.csv('data\/train.csv', header=True, inferSchema=True)  df.printSchema() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/um\/pc\/t8\/umpct8jps1qu4wc4r0jsgr22y6w.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/um\/pc\/t8\/umpct8jps1qu4wc4r0jsgr22y6w.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 pyspark \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 show<\/p>\n<pre><code class=\"python\">df.show() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/js\/v1\/kb\/jsv1kb9eyy_fxbqxut3qb1ddmti.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/js\/v1\/kb\/jsv1kb9eyy_fxbqxut3qb1ddmti.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435, \u0447\u0435\u043c \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u043c\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 prior_question_had_explanation \u043a \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0442\u0438\u043f\u0443<\/p>\n<pre><code class=\"python\">from pyspark.sql.types import IntegerType  df = df.withColumn('prior_question_had_explanation', df['prior_question_had_explanation'].cast(IntegerType())) df.printSchema() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/c3\/ps\/do\/c3psdo-4vobnagw3fdk4c9d65fg.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/c3\/ps\/do\/c3psdo-4vobnagw3fdk4c9d65fg.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u0443\u0441\u0442\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u041c\u0435\u0442\u043e\u0434 pandas_api \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 DataFrame \u0432 pandas-on-Spark DataFrame (\u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 pandas \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d).<\/p>\n<pre><code class=\"python\">df.pandas_api().isna().mean() # \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043d\u043e\u0435 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/li\/ei\/gp\/lieigpc6t3paw-nz4mvhalclgvy.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/li\/ei\/gp\/lieigpc6t3paw-nz4mvhalclgvy.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c.<\/p>\n<pre><code class=\"python\">df = df.dropna() df.pandas_api().isna().sum() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/1c\/20\/hq\/1c20hqmavtjkqef5iyirsmybouy.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/1c\/20\/hq\/1c20hqmavtjkqef5iyirsmybouy.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e pyspark \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u0438.<\/p>\n<h4>\u041c\u0430\u0442\u0440\u0438\u0446\u0430 \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u0438.<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 corr \u043a\u043b\u0430\u0441\u0441\u0430 Correlation \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0436\u0434\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/spark.apache.org\/docs\/3.1.3\/api\/python\/reference\/api\/pyspark.ml.feature.VectorAssembler.html\" rel=\"noopener noreferrer nofollow\">VectorAssembler<\/a><\/p>\n<blockquote>\n<p>\u0418\u0437 <a href=\"https:\/\/spark.apache.org\/docs\/latest\/api\/python\/reference\/api\/pyspark.ml.stat.Correlation.html\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>: column &#8212; \u0438\u043c\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u0438. \u042d\u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c <u>\u043e\u0431\u044a\u0435\u043a\u0442\u044b Vector<\/u>.<\/p>\n<\/blockquote>\n<pre><code class=\"python\">from pyspark.ml.stat import Correlation from pyspark.ml.feature import VectorAssembler import pandas as pd  # \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 Vector vector_col = \"corr_features\" assembler = VectorAssembler(inputCols=df.columns, outputCol=vector_col) df_vector = assembler.transform(df).select(vector_col)  # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u0438 \u0438 \u0442\u0443\u0442 \u0436\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 numpy \u0432\u0435\u043a\u0442\u043e\u0440 matrix = Correlation.corr(df_vector, vector_col).collect()[0][matrix.columns[0]].toArray() # \u0437\u0430\u043f\u0430\u0441\u0438\u0442\u0435\u0441\u044c \u043f\u043e\u043f\u043a\u043e\u0440\u043d\u043e\u043c, \u0434\u0430\u043d\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u043d\u0435 \u0431\u044b\u0441\u0442\u0440\u043e\u0435 corr_matrix_df = pd.DataFrame(data=matrix, columns = df.columns, index=df.columns) # \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0442\u0440\u0438\u0445 - \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432 pandas DataFrame <\/code><\/pre>\n<p>\u0412\u044b\u0432\u043e\u0434\u0438\u043c \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d<\/p>\n<pre><code class=\"python\">import seaborn as sns  import matplotlib.pyplot as plt plt.style.use('seaborn')  # plt.figure(figsize=(16,5))   sns.heatmap(corr_matrix_df,              xticklabels=corr_matrix_df.columns.values,             yticklabels=corr_matrix_df.columns.values,  cmap=\"Greens\", annot=True) plt.show() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/qw\/je\/d5\/qwjed5dwejynd7bypd-mtdcabjs.png\" width=\"auto\" height=\"auto\" data-src=\"https:\/\/habrastorage.org\/webt\/qw\/je\/d5\/qwjed5dwejynd7bypd-mtdcabjs.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, pyspark \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0441 \u043e\u0431\u044a\u0435\u043c\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u0441\u0435\u043c\u0438 \u043b\u044e\u0431\u0438\u043c\u043e\u0433\u043e pandas \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0443\u0436\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u041f\u0440\u0438\u0447\u0435\u043c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 pyspark \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u043e\u0447\u0435\u043d\u044c \u0441\u0445\u043e\u0436 \u0441 pandas. \u0410 \u0442\u0430\u043c, \u0433\u0434\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0447\u0438\u0441\u0442\u043e\u0433\u043e pyspark \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442, \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043c\u0435\u0442\u043e\u0434 pandas_api<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/708468\/\"> https:\/\/habr.com\/ru\/articles\/708468\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<\/th>\n<th>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<\/th>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Pandas &#8212; \u043e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a Python \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0430\u043c \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0440\u0430\u0441\u0442\u0443\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0418 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430\u0441\u0442\u0443\u043f\u0438\u0442 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0441\u0442\u0430\u043d\u0435\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a PySpark \u0432\u044b\u0440\u0443\u0447\u0430\u0435\u0442 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0438 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041d\u0443 \u0447\u0442\u043e \u0436\u0435, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043a\u0430\u0447\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043d\u0430\u0431\u043e\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 kaggle. \u0418\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 colab \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0441 kaggle \u043d\u0438\u0436\u0435:<\/p>\n<ol>\n<li>\n<p>\u0417\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u0440\u0430\u0437\u0434\u0435\u043b Account \u043d\u0430 <a href=\"http:\/\/kaggle.com\" rel=\"noopener noreferrer nofollow\">kaggle.com<\/a><\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u043b\u0438\u0441\u0442\u044b\u0432\u0430\u0435\u043c \u0432\u043d\u0438\u0437 \u0434\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u0430 API<\/p>\n<\/li>\n<li>\n<p>\u0416\u043c\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0443 Create New API Token, \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b kaggle.json<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043b\u0435\u0435 \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0432 Files \u043d\u0430 Google Colab, \u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u0430\u0436\u0434\u044b\u0435 12 \u0447\u0430\u0441\u043e\u0432 \u0441\u0435\u0441\u0441\u0438\u044f Google Colab \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f, \u0442\u043e \u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e Colab Notebooks \u043d\u0430 Google Drive<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<blockquote>\n<p>(<a href=\"https:\/\/www.kaggle.com\/general\/74235\" rel=\"noopener noreferrer nofollow\">https:\/\/www.kaggle.com\/general\/74235<\/a>) &#8212; \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435<\/p>\n<\/blockquote>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u043e\u043c <a href=\"https:\/\/www.kaggle.com\/c\/riiid-test-answer-prediction\" rel=\"noopener noreferrer nofollow\">Riiid Answer Correctness Prediction<\/a><\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u043e\u0434 \u043d\u0438\u0436\u0435 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0434\u0430\u0442\u0430\u0441\u0435\u0442, \u0432\u0441\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043b\u0435\u0436\u0430\u0442 \u0432 \u043f\u0430\u043f\u043a\u0435 data.<\/p>\n<pre><code class=\"python\"> ! pip install -q kaggle from google.colab import drive drive.mount('\/content\/drive') ! mkdir ~\/.kaggle ! cp '\/content\/drive\/MyDrive\/Colab Notebooks\/kaggle.json' ~\/.kaggle\/ # \u0444\u0430\u0439\u043b kaggle.json \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0432 \u043b\u044e\u0431\u0443\u044e \u043f\u0430\u043f\u043a\u0443 \u0432 Drive, \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b cp ! chmod 600 ~\/.kaggle\/kaggle.json ! kaggle competitions download -c 'riiid-test-answer-prediction' ! mkdir data ! unzip riiid-test-answer-prediction.zip -d data <\/code><\/pre>\n<p>\u0414\u0430\u0442\u0430\u0441\u0435\u0442, \u0441\u043a\u0430\u0436\u0435\u043c \u0442\u0430\u043a, \u043d\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439, \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0432\u0430\u0448\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u044b \u0432\u043f\u043e\u043b\u043d\u0435 \u0445\u0432\u0430\u0442\u0438\u0442 \u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 pandas. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0431\u0443\u0434\u0443 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Google Colab. \u0412 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 12 \u0413\u0411 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0443\u0447\u0435\u0431\u043d\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f \u044d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 pandas.<\/p>\n<h3>1. Pandas<\/h3>\n<pre><code class=\"python\">import pandas as pd  df_train = pd.read_csv('data\/train.csv',                         dtype={'content_id': 'int16',                                'content_type_id': 'int8',                                'task_container_id': 'int16',                                'user_answer': 'int8',                                'answered_correctly': 'int8',                                'prior_question_elapsed_time': 'float32'}) <\/code><\/pre>\n<p>\u0412\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<pre><code class=\"python\">df_train.head() <\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">df_train.info() <\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 4 \u0413\u0411 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u0447\u0442\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0440\u0435\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u0438, \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 colab \u0434\u043b\u044f \u043d\u0430\u0441.<\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u0443\u0441\u0442\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"python\">df_train.isna().sum() <\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">df_train[['prior_question_elapsed_time', 'prior_question_had_explanation']].isna().mean() <\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0418\u043c\u0435\u0435\u043c: \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 prior_question_elapsed_time \u0432\u0441\u0435\u0433\u043e \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 2% \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432, \u0432 prior_question_had_explanation \u0438 \u0442\u043e\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0435. \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u043c dropna \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 pandas \u0438&#8230;<\/p>\n<pre><code class=\"python\">df = df_train.dropna() <\/code><\/pre>\n<p>&#8230; \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<blockquote>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435, \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 read_csv \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0422\u043e\u0433\u0434\u0430 pandas \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043b \u0431\u044b \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443 \u0441 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043b\u0438\u0431\u043e \u0442\u0438\u043f int64, \u043b\u0438\u0431\u043e \u0442\u0438\u043f float64. \u0410 \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u043d\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u043d\u0435\u043c\u0430\u043b\u043e&#8230;<\/p>\n<\/blockquote>\n<p>\u0422\u0430\u043c, \u0433\u0434\u0435 \u043d\u0435 \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0441\u044f pandas, \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0435\u043c \u043a \u043f\u043e\u043c\u043e\u0449\u0438 pyspark.<\/p>\n<h3>2. Pyspark<\/h3>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c pyspark \u0438 pyarrow. Pyarrow \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 pyspark, \u0447\u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f<\/p>\n<pre><code>! pip install pyspark ! pip install pyarrow <\/code><\/pre>\n<pre><code class=\"python\">from pyspark.sql import SparkSession import os os.environ[\"PYARROW_IGNORE_TIMEZONE\"] = \"1\" # \u0431\u0435\u0437 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 \u0441 \u043f\u0440\u043e\u0441\u044c\u0431\u043e\u0439 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 1, \u0447\u0442\u043e \u043c\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0438 \u0434\u0435\u043b\u0430\u0435\u043c   spark = SparkSession.builder.getOrCreate() spark.conf.set(\"spark.sql.execution.arrow.pyspark.enabled\", \"true\") spark <\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0447\u0442\u0435\u043c \u043d\u0430\u0448 \u0444\u0430\u0439\u043b \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u0415\u0441\u043b\u0438 \u043c\u044b \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0434\u0438\u043d \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 inferSchema=True, pyspark \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442 \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438.<\/p>\n<pre><code class=\"python\">df = spark.read.csv('data\/train.csv', header=True, inferSchema=True)  df.printSchema() <\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 pyspark \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 show<\/p>\n<pre><code class=\"python\">df.show() <\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435, \u0447\u0435\u043c \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u043c\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 prior_question_had_explanation \u043a \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0442\u0438\u043f\u0443<\/p>\n<pre><code class=\"python\">from pyspark.sql.types import IntegerType  df = df.withColumn('prior_question_had_explanation', df['prior_question_had_explanation'].cast(IntegerType())) df.printSchema() <\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u0443\u0441\u0442\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u041c\u0435\u0442\u043e\u0434 pandas_api \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 DataFrame \u0432 pandas-on-Spark DataFrame (\u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 pandas \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d).<\/p>\n<pre><code class=\"python\">df.pandas_api().isna().mean() # \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043d\u043e\u0435 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 <\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c.<\/p>\n<pre><code class=\"python\">df = df.dropna() df.pandas_api().isna().sum() <\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e pyspark \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u0438.<\/p>\n<h4>\u041c\u0430\u0442\u0440\u0438\u0446\u0430 \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u0438.<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434 corr \u043a\u043b\u0430\u0441\u0441\u0430 Correlation \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0436\u0434\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/spark.apache.org\/docs\/3.1.3\/api\/python\/reference\/api\/pyspark.ml.feature.VectorAssembler.html\" rel=\"noopener noreferrer nofollow\">VectorAssembler<\/a><\/p>\n<blockquote>\n<p>\u0418\u0437 <a href=\"https:\/\/spark.apache.org\/docs\/latest\/api\/python\/reference\/api\/pyspark.ml.stat.Correlation.html\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>: column &#8212; \u0438\u043c\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u0438. \u042d\u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c <u>\u043e\u0431\u044a\u0435\u043a\u0442\u044b Vector<\/u>.<\/p>\n<\/blockquote>\n<pre><code class=\"python\">from pyspark.ml.stat import Correlation from pyspark.ml.feature import VectorAssembler import pandas as pd  # \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 Vector vector_col = \"corr_features\" assembler = VectorAssembler(inputCols=df.columns, outputCol=vector_col) df_vector = assembler.transform(df).select(vector_col)  # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u0438 \u0438 \u0442\u0443\u0442 \u0436\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 numpy \u0432\u0435\u043a\u0442\u043e\u0440 matrix = Correlation.corr(df_vector, vector_col).collect()[0][matrix.columns[0]].toArray() # \u0437\u0430\u043f\u0430\u0441\u0438\u0442\u0435\u0441\u044c \u043f\u043e\u043f\u043a\u043e\u0440\u043d\u043e\u043c, \u0434\u0430\u043d\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u043d\u0435 \u0431\u044b\u0441\u0442\u0440\u043e\u0435 corr_matrix_df = pd.DataFrame(data=matrix, columns = df.columns, index=df.columns) # \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0442\u0440\u0438\u0445 - \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432 pandas DataFrame <\/code><\/pre>\n<p>\u0412\u044b\u0432\u043e\u0434\u0438\u043c \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d<\/p>\n<pre><code class=\"python\">import seaborn as sns  import matplotlib.pyplot as plt plt.style.use('seaborn')  # plt.figure(figsize=(16,5))   sns.heatmap(corr_matrix_df,              xticklabels=corr_matrix_df.columns.values,             yticklabels=corr_matrix_df.columns.values,  cmap=\"Greens\", annot=True) plt.show() <\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, pyspark \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0441 \u043e\u0431\u044a\u0435\u043c\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u0441\u0435\u043c\u0438 \u043b\u044e\u0431\u0438\u043c\u043e\u0433\u043e pandas \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0443\u0436\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u041f\u0440\u0438\u0447\u0435\u043c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 pyspark \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u043e\u0447\u0435\u043d\u044c \u0441\u0445\u043e\u0436 \u0441 pandas. \u0410 \u0442\u0430\u043c, \u0433\u0434\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0447\u0438\u0441\u0442\u043e\u0433\u043e pyspark \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442, \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043c\u0435\u0442\u043e\u0434 pandas_api<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/708468\/\"> https:\/\/habr.com\/ru\/articles\/708468\/<\/a><br \/><\/br><\/br><\/p>\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-389930","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/389930","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=389930"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/389930\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=389930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=389930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=389930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}