94990


複数の座標から線分の組合せパターンを抽出した後、各線分と一つ一つの座標との組み合わせを一つの行にまとめたデータセットを作成したいです。  
（その後、行ごとに線分と座標の関係を計算することが目的です）

例えば３つの座標の場合、重複をまったく考慮せずにすべての組合わせを考える場合、  
線分の組合わせは３＊３、これに対してそれぞれの線分に各座標との組み合わせ＊３の、  
３＊３＊３の２７パターンができるかと存じます。

各パターンを一つの行に並べ、行ごとにひとつひとつの数値を使って線分と座標の関係を色々と計算したいです。

【こうしたいです】

[code]

         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]
    
[/code]

しかしながら、できたデータセットはひとつの枠の中に座標（[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)」は一読したものの、原因がわからないでいます）

分割方法（または組み合わせ方や、行毎に計算するなら他の方法があるなど）を何卒ご教示をいただけましたら幸いです。

【こうなってしまいました】

[code]

             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]
    
[/code]

失敗したコードは下記です。

[code]

    # ひとつの線分とあるひとつ座標のすべての組合せの行列を作成する
    # 座標サンプル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)
    
[/code]


CC BY-SA 4.0
2023-05-27T10:00:52.857
94989
2023-05-27T11:02:57.337
2023-05-27T10:21:34.347
43025
58484
question
python pandas 行列 dataframe
pandas DataFrameで座標が入れ子になっているデータセットの分割

[code]

    from itertools import product, chain
    import pandas as pd
    
    c1 = [1, 1] 
    c2 = [2, 2]
    c3 = [3, 3]
    
    # 線分と座標のすべての組合せを作成
    xy = [c1, c2, c3]
    linedotcomb = [xy, xy, xy]
    data = [[[i] for i in chain.from_iterable(l)] for l in product(*linedotcomb)]
    columns = map(''.join, product('ABC', 'xy'))
    
    df = pd.DataFrame(data=data, columns=columns)
    print(df)
    
    #      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]
    
                     :
    
    # 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]
    
[/code]


CC BY-SA 4.0
2023-05-27T11:02:57.337
94990
2023-05-27T11:02:57.337
47127
94989
answer