File size: 1,524 Bytes
43fd9b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pandas as pd
def expand_array_column(df: pd.DataFrame, column_name: str, prefix: str = None) -> pd.DataFrame:
    """
    Expand a column of sequence-like values into multiple scalar columns.
    
    Parameters:
    - df: pandas DataFrame with a column of list/array-like entries.
    - column_name: name of the column to expand.
    - prefix: optional prefix for new columns; defaults to column_name.
    
    Returns:
    - A new DataFrame with the original column dropped and new columns added.
    """
    # Extract the list/array values
    sequences = df[column_name].tolist()
    if not sequences:
        raise ValueError(f"Column '{column_name}' is empty.")
    
    # Determine vector length
    vec_length = len(sequences[0])
    # Use provided prefix or fallback to column name
    prefix = prefix or column_name
    new_column_names = [f"{prefix}_{i}" for i in range(vec_length)]
    
    # Build expanded DataFrame
    expanded_df = pd.DataFrame(sequences, index=df.index, columns=new_column_names)
    
    # Drop original column and concatenate
    df_dropped = df.drop(columns=[column_name])
    result_df = pd.concat([df_dropped, expanded_df], axis=1)
    
    return result_df

df=pd.read_parquet("./ecfp_and_properties/all_data_merged-cleaned-ecfp4-properties-sorted-columns.parquet")
result_df=expand_array_column(df,"Ecfp_4","ECFP")

output_file="./ecfp_and_properties/all_data_merged-cleaned-ecfp4-properties-sorted-columns-expanded-ecfp.parquet"
result_df.to_parquet(output_file, index=False)