<table class=”grid-look”> <thead class=”product-grid-top”> <tr> <td class=”nav prev”>&nbsp;</td> <td><div class=”swatch-option image ” option-type=”2″ option-id=”1346″ option-label=”BLACK” option-tooltip-thumb=”https://media-www.ec.rs-taichi.com/catalog/product/cache/79cd194851544f88bafc552bf5216e5d/r/s/rsu500tbk01.jpg” option-tooltip-value=”https://media-www.ec.rs-taichi.com/catalog/product/cache/455d758771d3747e7d5f3337b2de6a2c/r/s/rsu500tbk01.jpg” option-attr-code=”color” style=”background:url(https://media-www.ec.rs-taichi.com/catalog/product/cache/455d758771d3747e7d5f3337b2de6a2c/r/s/rsu500tbk01.jpg) no-repeat center; background-size:initial;”></div><div>BLACK</div></td> <td><div class=”swatch-option image ” option-type=”2″ option-id=”1347″ option-label=”GRAY” option-tooltip-thumb=”https://media-www.ec.rs-taichi.com/catalog/product/cache/79cd194851544f88bafc552bf5216e5d/r/s/rsu500tgy01.jpg” option-tooltip-value=”https://media-www.ec.rs-taichi.com/catalog/product/cache/455d758771d3747e7d5f3337b2de6a2c/r/s/rsu500tgy01.jpg” option-attr-code=”color” style=”background:url(https://media-www.ec.rs-taichi.com/catalog/product/cache/455d758771d3747e7d5f3337b2de6a2c/r/s/rsu500tgy01.jpg) no-repeat center; background-size:initial;”></div><div>GRAY</div></td> </tr> </thead> <tbody id=”product-grid” class=”product-grid-center”> <tr class=”item”> <td> <div class=”swatch-option text ” option-type=”0″ option-id=”1801″ option-label=”S” option-tooltip-thumb=”” option-tooltip-value=”” option-attr-code=”size”>S</div> </td> <td class=”no-line-height”> <span>在庫有り</span> </td> <td class=”no-line-height”> <span>在庫有り</span> </td> </tr> <tr class=”item”> <td> <div class=”swatch-option text ” option-type=”0″ option-id=”1796″ option-label=”M” option-tooltip-thumb=”” option-tooltip-value=”” option-attr-code=”size”>M</div> </td> <td class=”no-line-height”> <span>在庫有り</span> </td> <td class=”no-line-height”> <span>在庫有り</span> </td> </tr> <tr class=”item”> <td> <div class=”swatch-option text ” option-type=”0″ option-id=”1795″ option-label=”L” option-tooltip-thumb=”” option-tooltip-value=”” option-attr-code=”size”>L</div> </td> <td class=”no-line-height”> <span>廃番</span> </td> <td class=”no-line-height”> <span>在庫有り</span> </td> </tr> <tr class=”item”> <td> <div class=”swatch-option text ” option-type=”0″ option-id=”1800″ option-label=”XL” option-tooltip-thumb=”” option-tooltip-value=”” option-attr-code=”size”>XL</div> </td> <td class=”no-line-height”> <span>在庫有り</span> </td> <td class=”no-line-height”> <span>在庫有り</span> </td> </tr> </tbody> </table> 上記のデータと、下記のデータを付け合わせたい。 <table class=”item_size” style=”margin-left: auto; margin-right: auto;” border=”1″> <tbody> <tr> <td class=”xl68″ style=”text-align: left; font-weight: bold; font-size: 14px;” width=”250″ height=”24″>商品番号</td> <td class=”xl68″ style=”text-align: left; font-weight: bold; font-size: 14px;” width=”250″>Color</td> <td class=”xl68″ style=”text-align: left; font-weight: bold; font-size: 14px;” width=”250″>Size</td> <td class=”xl68″ style=”text-align: left; font-weight: bold; font-size: 14px;” width=”250″>JanCode</td> </tr> <tr> <td class=”xl68″ style=”text-align: left;” height=”24″>RSU500BK01L</td> <td class=”xl68″ style=”text-align: left;”>BLACK</td> <td class=”xl68″ style=”text-align: left;”>L</td> <td class=”xl68″ style=”text-align: left;”>4997035046706</td> </tr> <tr> <td class=”xl68″ style=”text-align: left;” height=”24″>RSU500BK01M</td> <td class=”xl68″ style=”text-align: left;”>BLACK</td> <td class=”xl68″ style=”text-align: left;”>M</td> <td class=”xl68″ style=”text-align: left;”>4997035046713</td> </tr> <tr> <td class=”xl68″ style=”text-align: left;” height=”24″>RSU500BK01S</td> <td class=”xl68″ style=”text-align: left;”>BLACK</td> <td class=”xl68″ style=”text-align: left;”>S</td> <td class=”xl68″ style=”text-align: left;”>4997035046720</td> </tr> <tr> <td class=”xl68″ style=”text-align: left;” height=”24″>RSU500BK01XL</td> <td class=”xl68″ style=”text-align: left;”>BLACK</td> <td class=”xl68″ style=”text-align: left;”>XL</td> <td class=”xl68″ style=”text-align: left;”>4997035046737</td> </tr> <tr> <td class=”xl68″ style=”text-align: left;” height=”24″>RSU500GY01L</td> <td class=”xl68″ style=”text-align: left;”>GRAY</td> <td class=”xl68″ style=”text-align: left;”>L</td> <td class=”xl68″ style=”text-align: left;”>4997035040247</td> </tr> <tr> <td class=”xl68″ style=”text-align: left;” height=”24″>RSU500GY01M</td> <td class=”xl68″ style=”text-align: left;”>GRAY</td> <td class=”xl68″ style=”text-align: left;”>M</td> <td class=”xl68″ style=”text-align: left;”>4997035040254</td> </tr> <tr> <td class=”xl68″ style=”text-align: left;” height=”24″>RSU500GY01S</td> <td class=”xl68″ style=”text-align: left;”>GRAY</td> <td class=”xl68″ style=”text-align: left;”>S</td> <td class=”xl68″ style=”text-align: left;”>4997035040261</td> </tr> <tr> <td class=”xl68″ style=”text-align: left;” height=”24″>RSU500GY01XL</td> <td class=”xl68″ style=”text-align: left;”>GRAY</td> <td class=”xl68″ style=”text-align: left;”>XL</td> <td class=”xl68″ style=”text-align: left;”>4997035040278</td> </tr> </tbody> </table>

両方のテーブルを結合して、新しいテーブルを作成する方法はいくつかあります。Pythonのパンダスライブラリを使用して、データフレームを操作することができます。以下はその一例です:

python
import pandas as pd # 最初のテーブルのデータ data1 = { 'Color': ['BLACK', 'GRAY', 'GRAY', 'BLACK'], 'Size': ['S', 'M', 'L', 'XL'], 'Stock': ['在庫有り', '在庫有り', '在庫有り', '在庫有り'] } # 2番目のテーブルのデータ data2 = { '商品番号': ['RSU500BK01L', 'RSU500BK01M', 'RSU500BK01S', 'RSU500BK01XL', 'RSU500GY01L', 'RSU500GY01M', 'RSU500GY01S', 'RSU500GY01XL'], 'Color': ['BLACK', 'BLACK', 'BLACK', 'BLACK', 'GRAY', 'GRAY', 'GRAY', 'GRAY'], 'Size': ['L', 'M', 'S', 'XL', 'L', 'M', 'S', 'XL'], 'JanCode': ['4997035046706', '4997035046713', '4997035046720', '4997035046737', '4997035040247', '4997035040254', '4997035040261', '4997035040278'] } # データフレームを作成 df1 = pd.DataFrame(data1) df2 = pd.DataFrame(data2) # カラム名が一致する場合はマージ merged_df = pd.merge(df1, df2, on=['Color', 'Size']) # 結果を表示 print(merged_df)

このコードでは、両方のテーブルをデータフレームに変換し、ColorSize のカラムで結合しています。結果のデータフレーム merged_df には、両方のテーブルのデータが組み合わされています。

未分類

Posted by ぼっち