Code Execution Output

Python Code Example


import pandas as pd

# Initial data
data = {
    "Recursion": [1],
    "Number of Ellipses": [3],
    "Number of Chords": [6],
    "Number of Foci": [6],
    "Number of Points P": [3],
    "Ellipses": [['E_1_a', 'E_1_b', 'E_1_c']],
    "Chords": [['C_1_a', 'C_1_b', 'C_1_c', 'C_1_d', 'C_1_e', 'C_1_f']],
    "Foci": [['F_1_a', 'F_1_b', 'F_1_c', 'F_1_d', 'F_1_e', 'F_1_f']],
    "Points P": [['P_1_a', 'P_1_b', 'P_1_c']],
    "Centers": [[(3.5, 0), (1.0, 0), (6.0, 0)]],
    "Points P Coordinates": [[(3.5000000000000004, 3.122498999199199), (1.7949984102035197, 0.9929526960901777), (5.20500158979648, 0.9929526960901777)]],
    "Chord Lengths": [[[4.0, 3.9999999999999996], [1.9968740067521995, 1.0031259939978001], [1.0031259939978003, 1.9968740067522]]]
}

df = pd.DataFrame(data)

# Unnesting the data into 6 rows
unnested_data = {
    "Recursion": [],
    "Ellipses": [],
    "Chords": [],
    "Foci": [],
    "Points P": [],
    "Centers": [],
    "Points P Coordinates": [],
    "Chord Lengths": []
}

for i in range(df["Number of Chords"][0]):
    ellipse_index = i % df["Number of Ellipses"][0]
    foci_index = i % df["Number of Foci"][0]
    point_index = i % df["Number of Points P"][0]
    center_index = i % len(df["Centers"][0])
    
    unnested_data["Recursion"].append(df["Recursion"][0])
    unnested_data["Ellipses"].append(df["Ellipses"][0][ellipse_index])
    unnested_data["Chords"].append(df["Chords"][0][i])
    unnested_data["Foci"].append(df["Foci"][0][foci_index])
    unnested_data["Points P"].append(df["Points P"][0][point_index])
    unnested_data["Centers"].append(df["Centers"][0][center_index])
    unnested_data["Points P Coordinates"].append(df["Points P Coordinates"][0][center_index])
    unnested_data["Chord Lengths"].append(df["Chord Lengths"][0][ellipse_index][i % 2])

unnested_df = pd.DataFrame(unnested_data)
display(unnested_df)

Output