{"id":324,"date":"2025-07-15T20:42:26","date_gmt":"2025-07-15T11:42:26","guid":{"rendered":"https:\/\/hooper-lab.com\/?p=324"},"modified":"2025-07-15T20:42:39","modified_gmt":"2025-07-15T11:42:39","slug":"10%ef%bc%9a%e3%81%9d%e3%81%ae%e4%bb%96%e3%81%aepython%e5%9f%ba%e7%a4%8e%ef%bc%88%e9%96%a2%e6%95%b0%e3%83%bbfor%e3%83%ab%e3%83%bc%e3%83%97%e3%83%bbif%e6%96%87%e3%83%bbloc-iloc%ef%bc%89","status":"publish","type":"post","link":"https:\/\/hooper-lab.com\/?p=324","title":{"rendered":"10\uff1a\u305d\u306e\u4ed6\u306ePython\u57fa\u790e\uff08\u95a2\u6570\u30fbfor\u30eb\u30fc\u30d7\u30fbif\u6587\u30fbloc\/iloc\uff09"},"content":{"rendered":"\n<div class=\"wp-block-buttons is-content-justification-right is-layout-flex wp-container-core-buttons-is-layout-d445cf74 wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/hooper-lab.com\/?p=287\">\u524d\u9805\u76ee\u3078<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\">\u6b21\u9805\u76ee\u3078<\/a><\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u305d\u306e\u4ed6\u306ePython\u57fa\u790e<\/strong><\/h4>\n\n\n\n<p>\u4eca\u307e\u3067Python\u3092\u52d5\u304b\u3057\u306a\u304c\u3089\u5b66\u3093\u3067\u304d\u3066\u3001\u6bb5\u3005\u3068\u30b9\u30e0\u30fc\u30ba\u306b\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u305f\u3068\u601d\u3044\u307e\u3059\u3002\u3053\u308c\u307e\u3067\u6271\u308f\u306a\u304b\u3063\u305f\u57fa\u790e\u306b\u3064\u3044\u3066\u3001\u672c\u7ae0\u3067\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002\u57fa\u672c\u7684\u306a\u96c6\u8a08\u306f\u57fa\u790e\u7de8\u3067\u5b66\u7fd2\u3057\u305f\u3053\u3068\u3092\u4f7f\u7528\u3059\u308c\u3070\u554f\u984c\u306a\u304f\u5bfe\u5fdc\u3067\u304d\u307e\u3059\u3002\u4eca\u56de\u3067\u57fa\u790e\u3092\u3057\u3063\u304b\u308a\u3068\u56fa\u3081\u3001\u5b9f\u8df5\u7de8\u3078\u6311\u6226\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u30c7\u30fc\u30bf\u6e96\u5099<\/strong><\/h4>\n\n\n\n<p>\u30c7\u30fc\u30bf\u306e\u6e96\u5099\u3068\u3057\u30662024-25\u30b7\u30fc\u30ba\u30f3\u306e<strong>\u5168\u30c1\u30fc\u30e0\u306e\u30a2\u30c9\u30d0\u30f3\u30b9\u30c8\u30b9\u30bf\u30c3\u30c4\uff08\u9ad8\u5ea6\u306a\u6307\u6a19\uff09<\/strong>\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\nfrom nba_api.stats.endpoints import leaguedashteamstats\n\nteam_stats = leaguedashteamstats.LeagueDashTeamStats(\n    season='2024-25',\n    measure_type_detailed_defense='Advanced'\n)\n\ndf_team = team_stats.get_data_frames()&#91;0]\ndf_team.head()<\/code><\/pre>\n\n\n\n<p>\u3053\u306e<code>df_team<\/code>\u306b\u306f\u3001<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30c1\u30fc\u30e0\u540d\uff08TEAM_NAME\uff09<\/li>\n\n\n\n<li>\u52dd\u7387\uff08W_PCT\uff09<\/li>\n\n\n\n<li>\u30cd\u30c3\u30c8\u30ec\u30fc\u30c6\u30a3\u30f3\u30b0\uff08NET_RATING\uff09<\/li>\n\n\n\n<li>\u30c8\u30a5\u30eb\u30fc\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0%\uff08TS_PCT\uff09<br>\u306a\u3069\u3001\u69d8\u3005\u306a\u6307\u6a19\u304c\u5165\u3063\u3066\u3044\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>loc\u3068iloc\uff1a\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u51fa\u3059\u65b9\u6cd5<\/strong><\/h4>\n\n\n\n<p><strong>\u2705 loc\uff1a\u300c\u30e9\u30d9\u30eb\uff08\u5217\u540d\u3084\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u540d\uff09\u300d\u3067\u6307\u5b9a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>team_name = df_team.loc&#91;0, 'TEAM_NAME']  # 0\u884c\u76ee\u306e\u30c1\u30fc\u30e0\u540d\nwin_pct = df_team.loc&#91;0, 'W_PCT']        # 0\u884c\u76ee\u306e\u52dd\u7387\nprint(f\"loc\u3067\u62bd\u51fa\uff1a{team_name}\u306e\u52dd\u7387\u306f{win_pct}\")<\/code><\/pre>\n\n\n\n<p><strong>\u2705 iloc\uff1a\u300c\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\uff080\u756a\u76ee\u30011\u756a\u76ee\uff09\u300d\u3067\u6307\u5b9a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>team_name_iloc = df_team.iloc&#91;0, 1]  # 0\u884c\u76ee\u30011\u5217\u76ee\u306e\u30c7\u30fc\u30bf\uff08TEAM_NAME\uff09\nwin_pct_iloc = df_team.iloc&#91;0, 4]    # 0\u884c\u76ee\u30014\u5217\u76ee\u306e\u30c7\u30fc\u30bf\uff08W_PCT\uff09\nprint(f\"iloc\u3067\u62bd\u51fa\uff1a{team_name_iloc}\u306e\u52dd\u7387\u306f{win_pct_iloc}\")<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u6307\u5b9a\u65b9\u6cd5<\/th><th>loc<\/th><th>iloc<\/th><\/tr><\/thead><tbody><tr><td>\u6307\u5b9a\u57fa\u6e96<\/td><td><strong>\u5217\u540d\u30fb\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u540d<\/strong><\/td><td><strong>\u756a\u53f7\uff080,1,2&#8230;\uff09<\/strong><\/td><\/tr><tr><td>\u4f8b<\/td><td><code><strong>loc[0, 'TEAM_NAME']<\/strong><\/code><\/td><td><code><strong>iloc[0, 1]<\/strong><\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>\u2705 \u6ce8\u610f<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5217\u540d\u304c\u308f\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u306f<code>loc<\/code>\u306e\u65b9\u304c\u308f\u304b\u308a\u3084\u3059\u3044<\/strong><\/li>\n\n\n\n<li><strong>\u5358\u7d14\u306b\u9806\u756a\u3067\u6307\u5b9a\u3057\u305f\u3044\u5834\u5408\u306f<code>iloc<\/code>\u304c\u4fbf\u5229<\/strong><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>if\u6587\uff1a\u6761\u4ef6\u306b\u3088\u3063\u3066\u51e6\u7406\u3092\u5909\u3048\u308b<\/strong><\/h4>\n\n\n\n<p>if\u6587\u306f\u3001<strong>\u300c\u3082\u3057\u301c\u306a\u3089\u300d\u300c\u305d\u3046\u3067\u306a\u3051\u308c\u3070\u300d<\/strong>\u3068\u3044\u3046\u6761\u4ef6\u5206\u5c90\u3092\u3059\u308b\u305f\u3081\u306e\u4ed5\u7d44\u307f\u3067\u3059\u3002<\/p>\n\n\n\n<p><strong>\u2705 \u4f8b\uff1a\u30cd\u30c3\u30c8\u30ec\u30fc\u30c6\u30a3\u30f3\u30b0\u304c\u30d7\u30e9\u30b9\u304b\u30de\u30a4\u30ca\u30b9\u304b\u5224\u5b9a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>team_name = df_team.loc&#91;0, 'TEAM_NAME']\nnet_rating = df_team.loc&#91;0, 'NET_RATING']\n\nif net_rating > 0:\n    print(f\"{team_name}\u306fNET_RATING\u304c\u30d7\u30e9\u30b9\u306e\u30c1\u30fc\u30e0\")\nelse:\n    print(f\"{team_name}\u306fNET_RATING\u304c\u30de\u30a4\u30ca\u30b9\u306e\u30c1\u30fc\u30e0\")<\/code><\/pre>\n\n\n\n<p>\u3053\u308c\u3067\u3001<strong>\u5f97\u5931\u70b9\u5dee\u304c\u30d7\u30e9\u30b9\u306a\u306e\u304b\u30de\u30a4\u30ca\u30b9\u306a\u306e\u304b<\/strong>\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u95a2\u6570\uff1a\u51e6\u7406\u3092\u307e\u3068\u3081\u3066\u518d\u5229\u7528\u3059\u308b\u4ed5\u7d44\u307f<\/strong><\/h4>\n\n\n\n<p>\u95a2\u6570\u306f\u3001<strong>\u3088\u304f\u4f7f\u3046\u51e6\u7406\u3092\u4e00\u3064\u306e\u540d\u524d\u306b\u307e\u3068\u3081\u308b<\/strong>\u4ed5\u7d44\u307f\u3067\u3059\u3002<br>\u3053\u308c\u306b\u3088\u308a\u3001<strong>\u540c\u3058\u51e6\u7406\u3092\u4f55\u5ea6\u3067\u3082\u4f7f\u3044\u307e\u308f\u305b\u307e\u3059<\/strong>\u3002<\/p>\n\n\n\n<p><strong>\u2705 \u4f8b\uff1a\u52dd\u7387\u304c60%\u4ee5\u4e0a\u306e\u30c1\u30fc\u30e0\u3092\u300c\u5f37\u3044\u300d\u3068\u5224\u5b9a\u3059\u308b\u95a2\u6570<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def is_strong_team(win_pct):\n    if win_pct >= 0.6:\n        return '\u5f37\u3044\u30c1\u30fc\u30e0'\n    else:\n        return '\u666e\u901a\u306e\u30c1\u30fc\u30e0'\n\nexample_win_pct = df_team.loc&#91;0, 'W_PCT']\nprint(f\"{df_team.loc&#91;0, 'TEAM_NAME']}\u306f\uff1a{is_strong_team(example_win_pct)}\")<\/code><\/pre>\n\n\n\n<p>\u3053\u306e\u95a2\u6570\u306f\u3001\u52dd\u7387\u304c60%\u4ee5\u4e0a\u306a\u3089\u300c\u5f37\u3044\u30c1\u30fc\u30e0\u300d\u3001\u305d\u308c\u672a\u6e80\u306f\u300c\u666e\u901a\u306e\u30c1\u30fc\u30e0\u300d\u3068\u5224\u5b9a\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>for\u30eb\u30fc\u30d7\uff1a\u5168\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u3066\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u3059\u308b<\/strong><\/h4>\n\n\n\n<p>for\u30eb\u30fc\u30d7\u306f\u3001<strong>\u30c7\u30fc\u30bf\u306e\u4e00\u3064\u4e00\u3064\u306b\u9806\u756a\u306b\u51e6\u7406\u3092\u884c\u3046<\/strong>\u6642\u306b\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p><strong>\u2705 \u4f8b\uff1a\u5168\u30c1\u30fc\u30e0\u306e\u52dd\u7387\u3092\u5224\u5b9a\u3057\u3066\u8868\u793a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for index, row in df_team.iterrows():\n    team_name = row&#91;'TEAM_NAME']\n    win_pct = row&#91;'W_PCT']\n    result = is_strong_team(win_pct)\n    print(f\"{team_name}\u306f{result}\")<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>df_team.iterrows()<\/code>\u306f\u3001\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3092<strong>1\u884c\u305a\u3064\u53d6\u308a\u51fa\u3059<\/strong>\u305f\u3081\u306e\u95a2\u6570\u3002<\/li>\n\n\n\n<li><code>row['TEAM_NAME']<\/code>\u306a\u3069\u3067\u3001\u305d\u306e\u884c\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u7d50\u679c\u306f\u4ee5\u4e0b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"324\" height=\"525\" src=\"https:\/\/hooper-lab.com\/wp-content\/uploads\/2025\/07\/image-26.png\" alt=\"\" class=\"wp-image-325\" srcset=\"https:\/\/hooper-lab.com\/wp-content\/uploads\/2025\/07\/image-26.png 324w, https:\/\/hooper-lab.com\/wp-content\/uploads\/2025\/07\/image-26-185x300.png 185w\" sizes=\"auto, (max-width: 324px) 100vw, 324px\" \/><\/figure>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306bfor\u30eb\u30fc\u30d7\u3092\u7528\u3044\u3066\u5168\u30c1\u30fc\u30e0\u306b\u5bfe\u3057\u3066\u3001\u95a2\u6570\u3092\u4f7f\u7528\u3057\u3066\u52dd\u7387\u306e\u5224\u5b9a\u3092\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u307e\u3068\u3081<\/strong><\/h4>\n\n\n\n<p>\u672c\u7ae0\u3067\u306e\u307e\u3068\u3081\u306f\u4ee5\u4e0b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u6a5f\u80fd<\/th><th>\u5f79\u5272<\/th><th>\u4f8b<\/th><\/tr><\/thead><tbody><tr><td><strong>loc \/ iloc<\/strong><\/td><td>\u30c7\u30fc\u30bf\u306e\u62bd\u51fa<\/td><td>\u30c1\u30fc\u30e0\u540d\u30fb\u52dd\u7387\u306a\u3069\u306e\u53d6\u5f97<\/td><\/tr><tr><td><strong>if\u6587<\/strong><\/td><td>\u6761\u4ef6\u306b\u5fdc\u3058\u305f\u5206\u5c90<\/td><td>NET_RATING\u306e\u30d7\u30e9\u30b9\u30fb\u30de\u30a4\u30ca\u30b9\u5224\u5b9a<\/td><\/tr><tr><td><strong>\u95a2\u6570<\/strong><\/td><td>\u51e6\u7406\u306e\u307e\u3068\u3081\u30fb\u518d\u5229\u7528<\/td><td>\u52dd\u7387\u5224\u5b9a<\/td><\/tr><tr><td><strong>for\u30eb\u30fc\u30d7<\/strong><\/td><td>\u7e70\u308a\u8fd4\u3057\u51e6\u7406<\/td><td>\u5168\u30c1\u30fc\u30e0\u3092\u5206\u985e<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u6700\u521d\u306f\u6163\u308c\u308b\u307e\u3067\u6642\u9593\u304c\u304b\u304b\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u975e\u5e38\u306b\u4fbf\u5229\u3067\u3059\u3057\u5927\u5bb9\u91cf\u306e\u30c7\u30fc\u30bf\u3092\u51e6\u7406\u3059\u308b\u3046\u3048\u3067\u5fc5\u8981\u4e0d\u53ef\u6b20\u306a\u51e6\u7406\u3067\u3059\u3002\u57fa\u790e\u3092\u56fa\u3081\u3066\u3001<strong>\u5b9f\u8df5\u7de8\u306b\u6311\u6226<\/strong>\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-right is-layout-flex wp-container-core-buttons-is-layout-d445cf74 wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/hooper-lab.com\/?p=287\">\u524d\u9805\u76ee\u3078<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\">\u6b21\u9805\u76ee\u3078<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u305d\u306e\u4ed6\u306ePython\u57fa\u790e \u4eca\u307e\u3067Python\u3092\u52d5\u304b\u3057\u306a\u304c\u3089\u5b66\u3093\u3067\u304d\u3066\u3001\u6bb5\u3005\u3068\u30b9\u30e0\u30fc\u30ba\u306b\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u305f\u3068\u601d\u3044\u307e\u3059\u3002\u3053\u308c\u307e\u3067\u6271\u308f\u306a\u304b\u3063\u305f\u57fa\u790e\u306b\u3064\u3044\u3066\u3001\u672c\u7ae0\u3067\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002\u57fa\u672c\u7684\u306a\u96c6\u8a08\u306f\u57fa\u790e\u7de8\u3067\u5b66\u7fd2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":326,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,4],"tags":[16,8,17,11,9,12],"class_list":["post-324","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-10","category-learning","tag-jupyterlab","tag-nba","tag-pandas","tag-python","tag-9","tag-12"],"_links":{"self":[{"href":"https:\/\/hooper-lab.com\/index.php?rest_route=\/wp\/v2\/posts\/324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hooper-lab.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hooper-lab.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hooper-lab.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hooper-lab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=324"}],"version-history":[{"count":1,"href":"https:\/\/hooper-lab.com\/index.php?rest_route=\/wp\/v2\/posts\/324\/revisions"}],"predecessor-version":[{"id":327,"href":"https:\/\/hooper-lab.com\/index.php?rest_route=\/wp\/v2\/posts\/324\/revisions\/327"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hooper-lab.com\/index.php?rest_route=\/wp\/v2\/media\/326"}],"wp:attachment":[{"href":"https:\/\/hooper-lab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hooper-lab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hooper-lab.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}