List2Table-D-Pandas

Sat 17 May 2025

import pandas as pd
from IPython.display import display

# Example list of tuples
data = [
    (1, 'Alice', 25),
    (2, 'Bob', 30),
    (3, 'Charlie', 35)
]

# Convert the list of tuples to a DataFrame
df = pd.DataFrame(data, columns=['ID', 'Name', 'Age'])

# Set display options
pd.set_option('display.max_rows', 100)
pd.set_option('display.max_columns', 100)

# Apply custom styling
styled_df = df.style.set_properties(**{'text-align': 'center'})

# Display the DataFrame
display(styled_df)
  ID Name Age
0 1 Alice 25
1 2 Bob 30
2 3 Charlie 35
def list2table(cdata):

    first_row = cdata[0]
    cols_count = len(first_row)

    col_list = []
    for idx in range(cols_count):
        col_list.append(f'col_{idx}')

    # Convert the list of tuples to a DataFrame
    df1 = pd.DataFrame(cdata, columns = col_list)

    # Set display options
    pd.set_option('display.max_rows', 100)
    pd.set_option('display.max_columns', 100)

    # Apply custom styling
    styled_df = df1.style.set_properties(**{'text-align': 'center'})

    # Display the DataFrame
    display(styled_df)
data1 = [
    (1, 'Raja', 25),
    (2, 'Bob', 30),
    (3, 'Charlie', 35)
]
list2table(data1)
  col_0 col_1 col_2
0 1 Raja 25
1 2 Bob 30
2 3 Charlie 35


Score: 5

Category: duckdb