Programming

 import pandas as pd


# Load the Excel file into a DataFrame

df = pd.read_excel("your_file.xlsx")


# Split the header into multiple columns based on ';'

header_split = df.columns[0].split(';')


# Create a new DataFrame to store the split values

split_values = pd.DataFrame(columns=header_split)


# Iterate through each row and split the values after ';'

for index, row in df.iterrows():

    values = row[df.columns[0]].split(';')

    # Pad the split values if there are fewer values than columns

    if len(values) < len(header_split):

        values += [''] * (len(header_split) - len(values))

    split_values.loc[index] = values


# Concatenate the split_values DataFrame with the original DataFrame

df = pd.concat([df, split_values], axis=1)


# Drop the original column containing the combined header and values

df.drop(columns=[df.columns[0]], inplace=True)


# Display the DataFrame

print(df)


Comments

Popular posts from this blog

card slot machine

Card Game In Python