{"id":409495,"date":"2024-06-29T20:49:45","date_gmt":"2024-06-29T20:49:45","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=409495"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=409495","title":{"rendered":"<span>Python \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0430 \u0431\u043b\u0430\u0433\u043e ETL<\/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<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0435\u0441\u044c\u043c\u0430 \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0430\u0451\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u0431\u0443\u0434\u044c \u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u043d\u0430 \u043f\u0443\u0442\u0438 \u0432 \u0431\u0430\u0437\u0443 \u0438\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0431\u0430\u0437\u044b \u043d\u0430 \u043f\u0443\u0442\u0438 \u0432 \u043e\u0442\u0447\u0435\u0442\u044b \u0438 \u0442.\u043f. \u0415\u0441\u043b\u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043a\u043e\u0440\u043e \u0437\u0430\u0433\u0440\u0443\u0441\u0442\u0438\u0442\u044c. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0451 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e, \u0441\u043a\u0430\u0436\u0435\u043c, \u0432 \u0432\u0438\u0434\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 <code>dict<\/code>-\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 (\u0444\u0443\u043d\u043a\u0446\u0438\u0438?) \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u043e\u043b\u0435\u043c. \u041d\u043e \u0443\u0436\u0435 \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c:<\/p>\n<ul>\n<li>\n<p>\u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u0443\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0430\u0433\u0440\u0435\u0433\u0430\u0446\u0438\u0439 \u0432 \u0432\u044b\u0448\u0435\u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0439 <code>dict<\/code>, \u0442\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 <a href=\"https:\/\/docs.python.org\/3\/library\/itertools.html#itertools.groupby\" rel=\"noopener noreferrer nofollow\">itertools.groupby<\/a> \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043f\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0449\u0435 \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0435\u0433\u043e \u043d\u0435\u0442)<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435, \u0441\u043a\u0430\u0436\u0435\u043c, \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043e\u0442\u0447\u0435\u0442\u0430, \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043e\u0431\u0445\u043e\u0434\u0430 <code>dict<\/code>-\u0430 \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u043f\u043e\u043b\u0435\u043c, \u0434\u0430 \u0435\u0449\u0435 \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u043b\u0438\u0448\u043d\u0438\u0445 \u0444-\u0439 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u043f\u043e\u043b\u0435 \u2014 \u044d\u0442\u043e \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443<\/p>\n<\/li>\n<li>\n<p>\u0432 python \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b join (\u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u043d\u0435\u0442\u0435 \u0432\u043e \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e\u0435 \u0438 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0435)<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0441\u0435\u0433\u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043b\u0435\u043d\u0438\u0432\u043e \u043f\u0438\u0441\u0430\u0442\u044c, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0443\u0436 \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0442\u044f\u0436\u0435\u043b\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c\u0438 \u0432 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 pipeline-\u044b<\/p>\n<\/li>\n<li>\n<p>\u0441\u043b\u043e\u0436\u043d\u043e (\u0435\u0441\u043b\u0438 \u0438 \u0432\u043e\u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e) \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/p>\n<\/li>\n<\/ul>\n<h2>pip install convtools<\/h2>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435, \u043d\u0430\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0442 \u043d\u0430 \u043c\u044b\u0441\u043b\u0438: &#171;\u0411\u044b\u043b\u043e \u0431\u044b \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0437 \u043f\u0438\u0442\u043e\u043d\u0430 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u0438\u0435 \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0446\u0435\u043f\u043b\u044f\u0442\u044c \u0434\u0440\u0443\u0433 \u0437\u0430 \u0434\u0440\u0443\u0433\u0430, \u0430 \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430\u044f \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u044f \u0443\u0436\u0435 \u043d\u0430 \u0440\u0443\u043a\u0430\u0445, \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u0437\u043a\u043e\u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434. \u041d\u0443 \u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u0431\u044b \u0437\u0430\u0438\u043c\u0435\u0442\u044c group_by &amp; join \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c.&#187;<\/p>\n<p>\u0421 \u044d\u0442\u0438\u043c\u0438 \u043c\u044b\u0441\u043b\u044f\u043c\u0438 \u0438 \u0431\u044b\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/github.com\/iTechArt\/convtools\" rel=\"noopener noreferrer nofollow\">convtools<\/a> (<em>conversion tools<\/em>). <\/p>\n<p><strong>\u041f\u0440\u0438\u0432\u0435\u0434\u0443 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p><code>c.item(key_or_index)<\/code> &#8212; \u0437\u0430\u0434\u0430\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c \u0438 \u043a\u043b\u044e\u0447\u0430\u043c (\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 <code>default=...<\/code> )<\/p>\n<\/li>\n<li>\n<p><code>c.attr(attr_name)<\/code> &#8212; \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c<\/p>\n<\/li>\n<li>\n<p><code>c.call_func(datetime.strptime, c.item(\"dt\"), \"%Y-%m-%d\")<\/code> &#8212; \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0447\u0430\u0441\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b)<\/p>\n<\/li>\n<li>\n<p><code>c.iter(c.item(\"id\"))<\/code> &#8212; \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e <code>(item[\"id\"] for item in input_data)<\/code><\/p>\n<\/li>\n<li>\n<p><code>c.this().call_method(\"replace\", \"abc\", \"cde\")<\/code> &#8212; \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e <code>input_data.replace(\"abc\", \"cde\")<\/code><\/p>\n<\/li>\n<li>\n<p><code>c.item(\"object_list\").pipe(any_other_conversion)<\/code> &#8212; \u0432\u044b\u0445\u043b\u043e\u043f \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432 \u0434\u0440\u0443\u0433\u0443\u044e \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u044e (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 group_by \/ join) \u0438\u043b\u0438 \u0444-\u044e<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u043a: group_by<\/strong><\/p>\n<pre><code class=\"python\">from convtools import conversion as c  input_data = [     {\"a\": 5, \"b\": \"foo\"},     {\"a\": 10, \"b\": \"foo\"},     {\"a\": 10, \"b\": \"bar\"},     {\"a\": 10, \"b\": \"bar\"},     {\"a\": 20, \"b\": \"bar\"}, ] # \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043f\u043e \"b\" \u0438 \u043d\u0430\u0439\u0434\u0435\u043c \u0441\u0443\u043c\u043c\u044b \u0438 \u043f\u0435\u0440\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \"a\" conv = (     c.group_by(c.item(\"b\"))     .aggregate(         {             \"b\": c.item(\"b\"),             \"a_first\": c.ReduceFuncs.First(c.item(\"a\")),             \"a_sum\": c.ReduceFuncs.Sum(c.item(\"a\")),         } # \u044d\u0442\u043e\u0442 dict \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c           # \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0435\u0439, \u0430 \u043c\u043e\u0436\u043d\u043e \u0438 \u0432\u043e\u0432\u0441\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0430 tuple     )     .gen_converter()  # \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u0434 \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438     # \u0435\u0441\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c black \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u044e\u0434\u0430 debug=True, \u0442\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432\u044b\u0432\u0435\u0434\u0435\u0442     # \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 )  assert conv(input_data) == [     {'b': 'foo', 'a_first': 5, 'a_sum': 15},     {'b': 'bar', 'a_first': 10, 'a_sum': 40}] ]<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u043a\u043e\u0434 group_by, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 gen_converter()<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"> def group_by__eu(data_):     global labels_     _none = v_rc     signature_to_agg_data__eu = defaultdict(AggData__eu)      for row__eu in data_:         agg_data__eu = signature_to_agg_data__eu[row__eu[\"b\"]]         if agg_data__eu.v0 is _none:             agg_data__eu.v0 = row__eu[\"a\"]             agg_data__eu.v1 = row__eu[\"a\"] or 0         else:             agg_data__eu.v1 = agg_data__eu.v1 + (row__eu[\"a\"] or 0)      return [         {             \"b\": signature__eu,             \"a_first\": (None if agg_data__eu.v0 is _none else agg_data__eu.v0),             \"a_sum\": (0 if agg_data__eu.v1 is _none else agg_data__eu.v1),         }         for signature__eu, agg_data__eu in signature_to_agg_data__eu.items()     ]   def converter_6s(data_):     global labels_     return group_by__eu(data_)<\/code><\/pre>\n<\/div>\n<\/details>\n<p><strong>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043d\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438: join<\/strong><\/p>\n<pre><code class=\"python\">from convtools import conversion as c  collection_1 = [     {\"id\": 1, \"name\": \"Nick\"},     {\"id\": 2, \"name\": \"Joash\"},     {\"id\": 3, \"name\": \"Bob\"}, ] collection_2 = [     {\"ID\": \"3\", \"age\": 17, \"country\": \"GB\"},     {\"ID\": \"2\", \"age\": 21, \"country\": \"US\"},     {\"ID\": \"1\", \"age\": 18, \"country\": \"CA\"}, ] input_data = (collection_1, collection_2)  converter = (     c.join(         c.item(0),  # collection_1 (\u0442.\u043a. \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 tuple)         c.item(1),  # collection_2         c.and_(             c.LEFT.item(\"id\") == c.RIGHT.item(\"ID\").as_type(int),             c.RIGHT.item(\"age\") >= 18,         ),  # \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f join         how=\"left\",     )  # \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 tuple-\u043e\u0432 (left_item, right_item)     .iter({  # \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u0434\u0438\u043a\u0442         \"id\": c.item(0, \"id\"),  # \u043e\u0442 \u043b\u0435\u0432\u043e\u0433\u043e \u0432\u043e\u0437\u044c\u043c\u0435\u043c id         \"name\": c.item(0, \"name\"),  # name \u043b\u0435\u0432\u043e\u0433\u043e         \"age\": c.item(1, \"age\", default=None),  # age \u043f\u0440\u0430\u0432\u043e\u0433\u043e         \"country\": c.item(1, \"country\", default=None),  # country \u043f\u0440\u0430\u0432\u043e\u0433\u043e     })     .as_type(list)  # \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043c \u043a \u043b\u0438\u0441\u0442\u0443, \u0442.\u043a. \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0441 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c     .gen_converter()  # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440 \u0438 \u0445\u0440\u0430\u043d\u0438\u043c \u0433\u0434\u0435 \u0443\u0434\u043e\u0431\u043d\u043e )  assert converter(input_data) == [     {'id': 1, 'name': 'Nick', 'age': 18, 'country': 'CA'},     {'id': 2, 'name': 'Joash', 'age': 21, 'country': 'US'},     {'id': 3, 'name': 'Bob', 'age': None, 'country': None}]<\/code><\/pre>\n<p>\u0414\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0432\u044b\u0448\u0435. \u0421\u0441\u044b\u043b\u043a\u0438 \u043d\u0438\u0436\u0435:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/iTechArt\/convtools\" rel=\"noopener noreferrer nofollow\">github convtools<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/pypi.org\/project\/convtools\/\" rel=\"noopener noreferrer nofollow\">pypi convtools<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/convtools.readthedocs.io\/en\/latest\/cheatsheet.html#\" rel=\"noopener noreferrer nofollow\">cheatsheet<\/a><\/p>\n<\/li>\n<\/ul>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044d\u0442\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0430\u0445\u0430\u0440\u0430 \u0432 \u0441\u0432\u043e\u0451\u043c \u043a\u043e\u0434\u0435, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u044f DRY-\u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0438 \u043d\u0435 \u0434\u0435\u043b\u0430\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0442.\u043a. \u0432 \u043d\u0435\u043c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043b\u0438\u0448\u043d\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u0446\u0438\u043a\u043b\u043e\u0432 \u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0444-\u0439.<\/p>\n<p>\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u043c\u044b\u0441\u043b\u044f\u043c\u0438 \/ \u043f\u043e\u0436\u0435\u043b\u0430\u043d\u0438\u044f\u043c\u0438. \u0421\u043f\u0430\u0441\u0438\u0431\u043e!<\/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\/569398\/\"> https:\/\/habr.com\/ru\/articles\/569398\/<\/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<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0435\u0441\u044c\u043c\u0430 \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0430\u0451\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u0431\u0443\u0434\u044c \u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u043d\u0430 \u043f\u0443\u0442\u0438 \u0432 \u0431\u0430\u0437\u0443 \u0438\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0431\u0430\u0437\u044b \u043d\u0430 \u043f\u0443\u0442\u0438 \u0432 \u043e\u0442\u0447\u0435\u0442\u044b \u0438 \u0442.\u043f. \u0415\u0441\u043b\u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043a\u043e\u0440\u043e \u0437\u0430\u0433\u0440\u0443\u0441\u0442\u0438\u0442\u044c. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0451 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e, \u0441\u043a\u0430\u0436\u0435\u043c, \u0432 \u0432\u0438\u0434\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 <code>dict<\/code>-\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 (\u0444\u0443\u043d\u043a\u0446\u0438\u0438?) \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u043e\u043b\u0435\u043c. \u041d\u043e \u0443\u0436\u0435 \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c:<\/p>\n<ul>\n<li>\n<p>\u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u0443\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0430\u0433\u0440\u0435\u0433\u0430\u0446\u0438\u0439 \u0432 \u0432\u044b\u0448\u0435\u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0439 <code>dict<\/code>, \u0442\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 <a href=\"https:\/\/docs.python.org\/3\/library\/itertools.html#itertools.groupby\" rel=\"noopener noreferrer nofollow\">itertools.groupby<\/a> \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043f\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0449\u0435 \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0435\u0433\u043e \u043d\u0435\u0442)<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435, \u0441\u043a\u0430\u0436\u0435\u043c, \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043e\u0442\u0447\u0435\u0442\u0430, \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043e\u0431\u0445\u043e\u0434\u0430 <code>dict<\/code>-\u0430 \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u043f\u043e\u043b\u0435\u043c, \u0434\u0430 \u0435\u0449\u0435 \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u043b\u0438\u0448\u043d\u0438\u0445 \u0444-\u0439 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u043f\u043e\u043b\u0435 \u2014 \u044d\u0442\u043e \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443<\/p>\n<\/li>\n<li>\n<p>\u0432 python \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b join (\u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u043d\u0435\u0442\u0435 \u0432\u043e \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e\u0435 \u0438 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0435)<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0441\u0435\u0433\u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043b\u0435\u043d\u0438\u0432\u043e \u043f\u0438\u0441\u0430\u0442\u044c, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0443\u0436 \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0442\u044f\u0436\u0435\u043b\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c\u0438 \u0432 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 pipeline-\u044b<\/p>\n<\/li>\n<li>\n<p>\u0441\u043b\u043e\u0436\u043d\u043e (\u0435\u0441\u043b\u0438 \u0438 \u0432\u043e\u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e) \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/p>\n<\/li>\n<\/ul>\n<h2>pip install convtools<\/h2>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435, \u043d\u0430\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0442 \u043d\u0430 \u043c\u044b\u0441\u043b\u0438: &#171;\u0411\u044b\u043b\u043e \u0431\u044b \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0437 \u043f\u0438\u0442\u043e\u043d\u0430 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u0438\u0435 \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0446\u0435\u043f\u043b\u044f\u0442\u044c \u0434\u0440\u0443\u0433 \u0437\u0430 \u0434\u0440\u0443\u0433\u0430, \u0430 \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430\u044f \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u044f \u0443\u0436\u0435 \u043d\u0430 \u0440\u0443\u043a\u0430\u0445, \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u0437\u043a\u043e\u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434. \u041d\u0443 \u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u0431\u044b \u0437\u0430\u0438\u043c\u0435\u0442\u044c group_by &amp; join \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c.&#187;<\/p>\n<p>\u0421 \u044d\u0442\u0438\u043c\u0438 \u043c\u044b\u0441\u043b\u044f\u043c\u0438 \u0438 \u0431\u044b\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/github.com\/iTechArt\/convtools\" rel=\"noopener noreferrer nofollow\">convtools<\/a> (<em>conversion tools<\/em>). <\/p>\n<p><strong>\u041f\u0440\u0438\u0432\u0435\u0434\u0443 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p><code>c.item(key_or_index)<\/code> &#8212; \u0437\u0430\u0434\u0430\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c \u0438 \u043a\u043b\u044e\u0447\u0430\u043c (\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 <code>default=...<\/code> )<\/p>\n<\/li>\n<li>\n<p><code>c.attr(attr_name)<\/code> &#8212; \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c<\/p>\n<\/li>\n<li>\n<p><code>c.call_func(datetime.strptime, c.item(\"dt\"), \"%Y-%m-%d\")<\/code> &#8212; \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0447\u0430\u0441\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b)<\/p>\n<\/li>\n<li>\n<p><code>c.iter(c.item(\"id\"))<\/code> &#8212; \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e <code>(item[\"id\"] for item in input_data)<\/code><\/p>\n<\/li>\n<li>\n<p><code>c.this().call_method(\"replace\", \"abc\", \"cde\")<\/code> &#8212; \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e <code>input_data.replace(\"abc\", \"cde\")<\/code><\/p>\n<\/li>\n<li>\n<p><code>c.item(\"object_list\").pipe(any_other_conversion)<\/code> &#8212; \u0432\u044b\u0445\u043b\u043e\u043f \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432 \u0434\u0440\u0443\u0433\u0443\u044e \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u044e (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 group_by \/ join) \u0438\u043b\u0438 \u0444-\u044e<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u043a: group_by<\/strong><\/p>\n<pre><code class=\"python\">from convtools import conversion as c  input_data = [     {\"a\": 5, \"b\": \"foo\"},     {\"a\": 10, \"b\": \"foo\"},     {\"a\": 10, \"b\": \"bar\"},     {\"a\": 10, \"b\": \"bar\"},     {\"a\": 20, \"b\": \"bar\"}, ] # \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043f\u043e \"b\" \u0438 \u043d\u0430\u0439\u0434\u0435\u043c \u0441\u0443\u043c\u043c\u044b \u0438 \u043f\u0435\u0440\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \"a\" conv = (     c.group_by(c.item(\"b\"))     .aggregate(         {             \"b\": c.item(\"b\"),             \"a_first\": c.ReduceFuncs.First(c.item(\"a\")),             \"a_sum\": c.ReduceFuncs.Sum(c.item(\"a\")),         } # \u044d\u0442\u043e\u0442 dict \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c           # \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0435\u0439, \u0430 \u043c\u043e\u0436\u043d\u043e \u0438 \u0432\u043e\u0432\u0441\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0430 tuple     )     .gen_converter()  # \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u0434 \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438     # \u0435\u0441\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c black \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u044e\u0434\u0430 debug=True, \u0442\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432\u044b\u0432\u0435\u0434\u0435\u0442     # \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 )  assert conv(input_data) == [     {'b': 'foo', 'a_first': 5, 'a_sum': 15},     {'b': 'bar', 'a_first': 10, 'a_sum': 40}] ]<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u043a\u043e\u0434 group_by, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 gen_converter()<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"> def group_by__eu(data_):     global labels_     _none = v_rc     signature_to_agg_data__eu = defaultdict(AggData__eu)      for row__eu in data_:         agg_data__eu = signature_to_agg_data__eu[row__eu[\"b\"]]         if agg_data__eu.v0 is _none:             agg_data__eu.v0 = row__eu[\"a\"]             agg_data__eu.v1 = row__eu[\"a\"] or 0         else:             agg_data__eu.v1 = agg_data__eu.v1 + (row__eu[\"a\"] or 0)      return [         {             \"b\": signature__eu,             \"a_first\": (None if agg_data__eu.v0 is _none else agg_data__eu.v0),             \"a_sum\": (0 if agg_data__eu.v1 is _none else agg_data__eu.v1),         }         for signature__eu, agg_data__eu in signature_to_agg_data__eu.items()     ]   def converter_6s(data_):     global labels_     return group_by__eu(data_)<\/code><\/pre>\n<\/div>\n<\/details>\n<p><strong>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043d\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438: join<\/strong><\/p>\n<pre><code class=\"python\">from convtools import conversion as c  collection_1 = [     {\"id\": 1, \"name\": \"Nick\"},     {\"id\": 2, \"name\": \"Joash\"},     {\"id\": 3, \"name\": \"Bob\"}, ] collection_2 = [     {\"ID\": \"3\", \"age\": 17, \"country\": \"GB\"},     {\"ID\": \"2\", \"age\": 21, \"country\": \"US\"},     {\"ID\": \"1\", \"age\": 18, \"country\": \"CA\"}, ] input_data = (collection_1, collection_2)  converter = (     c.join(         c.item(0),  # collection_1 (\u0442.\u043a. \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 tuple)         c.item(1),  # collection_2         c.and_(             c.LEFT.item(\"id\") == c.RIGHT.item(\"ID\").as_type(int),             c.RIGHT.item(\"age\") >= 18,         ),  # \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f join         how=\"left\",     )  # \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 tuple-\u043e\u0432 (left_item, right_item)     .iter({  # \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u0434\u0438\u043a\u0442         \"id\": c.item(0, \"id\"),  # \u043e\u0442 \u043b\u0435\u0432\u043e\u0433\u043e \u0432\u043e\u0437\u044c\u043c\u0435\u043c id         \"name\": c.item(0, \"name\"),  # name \u043b\u0435\u0432\u043e\u0433\u043e         \"age\": c.item(1, \"age\", default=None),  # age \u043f\u0440\u0430\u0432\u043e\u0433\u043e         \"country\": c.item(1, \"country\", default=None),  # country \u043f\u0440\u0430\u0432\u043e\u0433\u043e     })     .as_type(list)  # \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043c \u043a \u043b\u0438\u0441\u0442\u0443, \u0442.\u043a. \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0441 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c     .gen_converter()  # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440 \u0438 \u0445\u0440\u0430\u043d\u0438\u043c \u0433\u0434\u0435 \u0443\u0434\u043e\u0431\u043d\u043e )  assert converter(input_data) == [     {'id': 1, 'name': 'Nick', 'age': 18, 'country': 'CA'},     {'id': 2, 'name': 'Joash', 'age': 21, 'country': 'US'},     {'id': 3, 'name': 'Bob', 'age': None, 'country': None}]<\/code><\/pre>\n<p>\u0414\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0432\u044b\u0448\u0435. \u0421\u0441\u044b\u043b\u043a\u0438 \u043d\u0438\u0436\u0435:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/iTechArt\/convtools\" rel=\"noopener noreferrer nofollow\">github convtools<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/pypi.org\/project\/convtools\/\" rel=\"noopener noreferrer nofollow\">pypi convtools<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/convtools.readthedocs.io\/en\/latest\/cheatsheet.html#\" rel=\"noopener noreferrer nofollow\">cheatsheet<\/a><\/p>\n<\/li>\n<\/ul>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044d\u0442\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0430\u0445\u0430\u0440\u0430 \u0432 \u0441\u0432\u043e\u0451\u043c \u043a\u043e\u0434\u0435, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u044f DRY-\u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0438 \u043d\u0435 \u0434\u0435\u043b\u0430\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0442.\u043a. \u0432 \u043d\u0435\u043c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043b\u0438\u0448\u043d\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u0446\u0438\u043a\u043b\u043e\u0432 \u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0444-\u0439.<\/p>\n<p>\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u043c\u044b\u0441\u043b\u044f\u043c\u0438 \/ \u043f\u043e\u0436\u0435\u043b\u0430\u043d\u0438\u044f\u043c\u0438. \u0421\u043f\u0430\u0441\u0438\u0431\u043e!<\/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\/569398\/\"> https:\/\/habr.com\/ru\/articles\/569398\/<\/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-409495","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/409495","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=409495"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/409495\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=409495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=409495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=409495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}