複数の座標から線分の組合せパターンを抽出した後、各線分と一つ一つの座標との組み合わせを一つの行にまとめたデータセットを作成したいです。 (その後、行ごとに線分と座標の関係を計算することが目的です) 例えば3つの座標の場合、重複をまったく考慮せずにすべての組合わせを考える場合、 線分の組合わせは3*3、これに対してそれぞれの線分に各座標との組み合わせ*3の、 3*3*3の27パターンができるかと存じます。 各パターンを一つの行に並べ、行ごとにひとつひとつの数値を使って線分と座標の関係を色々と計算したいです。 【こうしたいです】 ``` Ax Ay Bx By Cx Cy 0 [1] [1] [1] [1] [1] [1] ←行毎に別途計算を行うことが目的です 1 [1] [1] [1] [1] [2] [2] 2 [1] [1] [1] [1] [3] [3] 3 [1] [1] [2] [2] [1] [1] 4 [1] [1] [2] [2] [2] [2] 5 [1] [1] [2] [2] [3] [3] 6 [1] [1] [3] [3] [1] [1] 7 [1] [1] [3] [3] [2] [2] 8 [1] [1] [3] [3] [3] [3] 9 [2] [2] [1] [1] [1] [1] 10 [2] [2] [1] [1] [2] [2] 11 [2] [2] [1] [1] [3] [3] 12 [2] [2] [2] [2] [1] [1] 13 [2] [2] [2] [2] [2] [2] 14 [2] [2] [2] [2] [3] [3] 15 [2] [2] [3] [3] [1] [1] 16 [2] [2] [3] [3] [2] [2] 17 [2] [2] [3] [3] [3] [3] 18 [3] [3] [1] [1] [1] [1] 19 [3] [3] [1] [1] [2] [2] 20 [3] [3] [1] [1] [3] [3] 21 [3] [3] [2] [2] [1] [1] 22 [3] [3] [2] [2] [2] [2] 23 [3] [3] [2] [2] [3] [3] 24 [3] [3] [3] [3] [1] [1] 25 [3] [3] [3] [3] [2] [2] 26 [3] [3] [3] [3] [3] [3] ``` しかしながら、できたデータセットはひとつの枠の中に座標([x座標,y座標])が入る形になっていて、分割しようと試みましたが、解決方法を見つけることができませんでした。 (「<https://ja.stackoverflow.com/questions/80570/%E4%B8%80%E3%81%A4%E3%81%AE%E3%82%AB%E3%83%A9%E3%83%A0%E3%81%AE%E4%B8%AD%E3%81%AB%E3%83%AA%E3%82%B9%E3%83%88%E3%81%A7%E3%83%87%E3%83%BC%E3%82%BF%E3%81%8C%E5%85%A5%E3%81%A3%E3%81%A6%E3%81%84%E3%82%8B%E5%A0%B4%E5%90%88-%E3%83%AA%E3%82%B9%E3%83%88%E3%81%AE%E5%90%84%E8%A6%81%E7%B4%A0%E3%82%92%E5%88%86%E5%89%B2%E3%81%97%E3%81%A6%E6%96%B0%E3%81%9F%E3%81%AB%E5%88%97%E3%82%92%E5%A2%97%E3%82%84%E3%81%97-%E5%90%84%E8%A6%81%E7%B4%A0%E3%82%92%E3%83%80%E3%83%9F%E3%83%BC%E5%A4%89%E6%95%B0%E5%8C%96%E6%96%B9%E6%B3%95%E3%81%AF%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99%E3%81%8B?newreg=e83a98fb50eb461cb07c36573a05f0c4>」は一読したものの、原因がわからないでいます) 分割方法(または組み合わせ方や、行毎に計算するなら他の方法があるなど)を何卒ご教示をいただけましたら幸いです。 【こうなってしまいました】 ``` A B C 0 [1, 1] [1, 1] [1, 1] 1 [1, 1] [1, 1] [2, 2] 2 [1, 1] [1, 1] [3, 3] 3 [1, 1] [2, 2] [1, 1] 4 [1, 1] [2, 2] [2, 2] 5 [1, 1] [2, 2] [3, 3] 6 [1, 1] [3, 3] [1, 1] 7 [1, 1] [3, 3] [2, 2] 8 [1, 1] [3, 3] [3, 3] 9 [2, 2] [1, 1] [1, 1] 10 [2, 2] [1, 1] [2, 2] 11 [2, 2] [1, 1] [3, 3] 12 [2, 2] [2, 2] [1, 1] 13 [2, 2] [2, 2] [2, 2] 14 [2, 2] [2, 2] [3, 3] 15 [2, 2] [3, 3] [1, 1] 16 [2, 2] [3, 3] [2, 2] 17 [2, 2] [3, 3] [3, 3] 18 [3, 3] [1, 1] [1, 1] 19 [3, 3] [1, 1] [2, 2] 20 [3, 3] [1, 1] [3, 3] 21 [3, 3] [2, 2] [1, 1] 22 [3, 3] [2, 2] [2, 2] 23 [3, 3] [2, 2] [3, 3] 24 [3, 3] [3, 3] [1, 1] 25 [3, 3] [3, 3] [2, 2] 26 [3, 3] [3, 3] [3, 3] ``` 失敗したコードは下記です。 ```py # ひとつの線分とあるひとつ座標のすべての組合せの行列を作成する # 座標サンプル3点 c1=[1,1] c2=[2,2] c3=[3,3] # 線分と座標のすべての組合せを作成 xy=[c1, c2, c3] print(xy) linedotcomb = [xy, xy, xy] print(linedotcomb) from itertools import product import pandas as pd df = pd.DataFrame(product(*linedotcomb), columns=list("ABC")) print(df) # 分割しようと試みて失敗 for column_name in df: print(column_name) s = df["A"] s.astype(str).str.replace(r'{|}|"', "", regex=True).str.get_dummies(',') print(s) ```