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)
print(unnested_df.to_html(index=False))
Output
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th>Recursion</th>
<th>Ellipses</th>
<th>Chords</th>
<th>Foci</th>
<th>Points P</th>
<th>Centers</th>
<th>Points P Coordinates</th>
<th>Chord Lengths</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>E_1_a</td>
<td>C_1_a</td>
<td>F_1_a</td>
<td>P_1_a</td>
<td>(3.5, 0)</td>
<td>(3.5000000000000004, 3.122498999199199)</td>
<td>4.000000</td>
</tr>
<tr>
<td>1</td>
<td>E_1_b</td>
<td>C_1_b</td>
<td>F_1_b</td>
<td>P_1_b</td>
<td>(1.0, 0)</td>
<td>(1.7949984102035197, 0.9929526960901777)</td>
<td>1.003126</td>
</tr>
<tr>
<td>1</td>
<td>E_1_c</td>
<td>C_1_c</td>
<td>F_1_c</td>
<td>P_1_c</td>
<td>(6.0, 0)</td>
<td>(5.20500158979648, 0.9929526960901777)</td>
<td>1.003126</td>
</tr>
<tr>
<td>1</td>
<td>E_1_a</td>
<td>C_1_d</td>
<td>F_1_d</td>
<td>P_1_a</td>
<td>(3.5, 0)</td>
<td>(3.5000000000000004, 3.122498999199199)</td>
<td>4.000000</td>
</tr>
<tr>
<td>1</td>
<td>E_1_b</td>
<td>C_1_e</td>
<td>F_1_e</td>
<td>P_1_b</td>
<td>(1.0, 0)</td>
<td>(1.7949984102035197, 0.9929526960901777)</td>
<td>1.996874</td>
</tr>
<tr>
<td>1</td>
<td>E_1_c</td>
<td>C_1_f</td>
<td>F_1_f</td>
<td>P_1_c</td>
<td>(6.0, 0)</td>
<td>(5.20500158979648, 0.9929526960901777)</td>
<td>1.996874</td>
</tr>
</tbody>
</table>
Data as Table
No DataFrame found in the output.