{"id":2701,"date":"2021-03-03T17:05:16","date_gmt":"2021-03-03T08:05:16","guid":{"rendered":"https:\/\/qol-kk.com\/wp2\/?p=2701"},"modified":"2021-03-03T17:05:16","modified_gmt":"2021-03-03T08:05:16","slug":"post-2701","status":"publish","type":"post","link":"https:\/\/qol-kk.com\/wp2\/blog\/2021\/03\/03\/post-2701\/","title":{"rendered":"Django\uff1a\u300cpandas\u306e\u96c6\u8a08\u7d50\u679c\u3092Template\u3067For\u30eb\u30fc\u30d7\u3057\u305f\u3089Index\u304c\u6d88\u3048\u305f\u300d\u3092\u89e3\u6d88\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<h2>Django\uff1a\u300cpandas\u306e\u96c6\u8a08\u7d50\u679c\u3092Template\u3067For\u30eb\u30fc\u30d7\u3057\u305f\u3089Index\u304c\u6d88\u3048\u305f\u300d\u3092\u89e3\u6d88\u3059\u308b\u65b9\u6cd5<\/h2>\n<p>SQL\u304b\u3089\u5024\u3092\u53d6\u308a\u51fa\u3057\u3066DataFrame\u306b\u3057\u3066\u96c6\u8a08\u3057\u3066Template\u306b\u9001\u308b\u3002<br \/>\nDjango\u3067\u30b7\u30b9\u30c6\u30e0\u3092\u7d44\u3093\u3067\u3044\u308c\u3070\u4f55\u5ea6\u3082\u884c\u3046\u3053\u3068\u306b\u306a\u308b\u51e6\u7406\u3067\u3059\u3002<br \/>\n\u3053\u306e\u6642\u3064\u307e\u3065\u304f\u30dd\u30a4\u30f3\u30c8\u306e\u4e00\u3064\u306b\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u53d6\u308a\u51fa\u3057\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<div class=\"borderBox\">\n<p>pandas\u306e\u96c6\u8a08\u7d50\u679c\u3092Template\u3067For\u30eb\u30fc\u30d7\u3057\u305f\u3051\u3069Index\u304c\u53d6\u308a\u51fa\u305b\u306a\u3044<\/p>\n<\/div>\n<p>\u30b7\u30f3\u30d7\u30eb\u306aFor in \u30eb\u30fc\u30d7\u3060\u3068\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30d5\u30a3\u30fc\u30eb\u30c9\u89e6\u308c\u306a\u3044\u3093\u3067\u3059\u3002\u79c1\u3082\u4f55\u56de\u8abf\u3079\u305f\u4e8b\u304b...\u3002<\/p>\n<h3>\u5177\u4f53\u7684\u306a\u4e8b\u4f8b\u3067\u78ba\u8a8d<\/h3>\n<p>\u3053\u3093\u306a\u30c7\u30fc\u30bf\u3067\u8003\u3048\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre>print(df)\r\n#       col1\r\n# row1    10\r\n# row2    20\r\n# row3    30<\/pre>\n<h4>\u30b7\u30f3\u30d7\u30eb\u306aFor\u30eb\u30fc\u30d7\u3067\u66f8\u304f\u3068\u6700\u521d\u306e\u30ab\u30e9\u30e0\u304c\u6d88\u3048\u308b<\/h4>\n<pre>{% for val in df %}\r\n    {{val}}\r\n{% endfor %}\r\n\r\n# \u7d50\u679c {{val}}\r\n10\r\n20\r\n30<\/pre>\n<p>{{ val.col1 }}\u3068\u304b{{ val['col1'] }}\u3068\u304b\u3064\u3044\u3064\u3044\u66f8\u3044\u3066\u3057\u307e\u3044\u307e\u3059\u304c\u3001\u3069\u3061\u3089\u3082\u53d6\u5f97\u3067\u304d\u307e\u305b\u3093\u3002<br \/>\nval.col1 \u3067\u306f\u4e00\u5207\u306e\u5024\u306a\u3057\u3002val['col1'] \u3067\u306f\u3010TemplateSyntaxError\u3011\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<h4>Index\u3092\u53d6\u308a\u51fa\u3059\u305f\u3081\u306b\u306f\u5909\u6570\u30922\u3064\u7528\u610f\u3059\u308b<\/h4>\n<pre>{% for index,val in df.items %}\r\n    {{index}} \/ {{val}}\r\n{% endfor %}\r\n\r\n# \u7d50\u679c\r\nrow1 \/ 10\r\nrow2 \/ 20\r\nrow3 \/ 30<\/pre>\n<p>\u8f9e\u66f8\u578b\u306ekey\u3092\u53d6\u308a\u51fa\u3059\u6642\u3068\u540c\u3058\u3088\u3046\u306b\u5909\u6570\u30922\u3064\u7528\u610f\u3057\u307e\u3059\u3002<br \/>\n\u3053\u306e\u8f9e\u66f8\u578b\u3068\u540c\u3058\u65b9\u5f0f\u3067DataFrame\u578b\u306eIndex\u306e\u5024\u3082\u53d6\u308a\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u305b\u3063\u304b\u304f\u96c6\u8a08\u3057\u3066\u3082\u300e\u4f55\u306e\u96c6\u8a08\u304b\u300f\u304c\u308f\u304b\u3089\u306a\u3044\u3068\u610f\u5473\u306a\u3044\u3067\u3059\u304b\u3089\u306d\u3002<br \/>\nTemplate\u3067\u306f label\u3068\u5024\u3067\u8868\u793a\u3059\u308b\u4e8b\u304c\u591a\u3044\u306e\u3067Pandas\u3092\u305d\u306e\u307e\u307e\u6e21\u3057\u305f\u5834\u5408\u306f\u591a\u7528\u3059\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n<h3>\u307e\u3068\u3081<\/h3>\n<p>\u6700\u521d\u306e\u3053\u308d\u306f\u308f\u3056\u308f\u3056LIST\u306b\u3057\u3066Template\u3078\u6e21\u3057\u3066\u307e\u3057\u305f\u304c\u3001\u3053\u308c\u3092\u899a\u3048\u308c\u3070Pandas\u306e\u307e\u307e\u3067OK\u306a\u306e\u3067\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<p>For\u30eb\u30fc\u30d7\u306b\u306f2\u3064\u306e\u5909\u6570\u3092\u4f7f\u3044\u65b9\u6cd5\u4ee5\u5916\u306b{% empty %}\u306a\u3093\u3066\u9805\u76ee\u3092\u7528\u610f\u3057\u3066\u30ea\u30b9\u30c8\u306e\u4e2d\u8eab\u304c\u306a\u3044\u6642\u306e\u51e6\u7406\u3092\u63cf\u304f\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002For\u30eb\u30fc\u30d7\u5185\u306bIf\u6587\u66f8\u3044\u3066\u51e6\u7406\u3057\u305f\u308a\u3057\u3066\u307e\u3057\u305f\u3051\u3069\u3001\u3053\u3044\u3064\u3042\u308c\u3070\u4e0d\u8981\u307f\u305f\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Django\uff1a\u300cpandas\u306e\u96c6\u8a08\u7d50\u679c\u3092Template\u3067For\u30eb\u30fc\u30d7\u3057\u305f\u3089Index\u304c\u6d88\u3048\u305f\u300d\u3092\u89e3\u6d88\u3059\u308b\u65b9\u6cd5 SQL\u304b\u3089\u5024\u3092\u53d6\u308a\u51fa\u3057\u3066DataFrame\u306b\u3057\u3066\u96c6\u8a08\u3057\u3066Template\u306b\u9001\u308b\u3002 Django\u3067\u30b7\u30b9\u30c6\u30e0\u3092\u7d44 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2173,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","_lightning_design_setting":[],"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[38],"tags":[862,814,955,425,861,147],"class_list":["post-2701","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-memorandum","tag-dataframe","tag-django","tag-for","tag-index","tag-pandas","tag-python"],"veu_head_title_object":{"title":"","add_site_title":""},"jetpack_publicize_connections":[],"jetpack-related-posts":[],"jetpack_sharing_enabled":false,"jetpack_featured_media_url":"https:\/\/qol-kk.com\/wp2\/wp-content\/uploads\/2020\/11\/python.png","_links":{"self":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/2701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/comments?post=2701"}],"version-history":[{"count":0,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/2701\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/media\/2173"}],"wp:attachment":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/media?parent=2701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/categories?post=2701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/tags?post=2701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}