Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.3 kB
1
Indexable
Never
import pandas as pd

# Read input from Excel file
input_df = pd.read_excel('input_file.xlsx')

# Strip whitespace from columns
input_df['Requirement(s)'] = input_df['Requirement(s)'].str.strip()
input_df['Specification(s)'] = input_df['Specification(s)'].str.strip()
input_df['Software Features'] = input_df['Software Features'].str.strip()

# Fill NaN values in 'Specification(s)' column with an empty string
input_df['Specification(s)'].fillna("", inplace=True)

# Group by Requirement(s) and Specification(s) and aggregate Software Features
output_df = input_df.groupby(['Requirement(s)', 'Specification(s)'])['Software Features'].apply(lambda x: ', '.join(x)).reset_index()

# Print the output in the desired format
print("| Requirement(s) | Specification(s) | Software Features |")
print("|----------------|-------------------|-------------------|")
for index, row in output_df.iterrows():
    requirement = row['Requirement(s)']
    specification = row['Specification(s)']
    features = row['Software Features']
    if specification == "":
        print(f"| {requirement} |  | {features} |")
    else:
        print(f"| {requirement} | {specification} | {features} |")

# Save the output to an Excel file
output_df.to_excel('output_file.xlsx', index=False)
Leave a Comment