import pandas as pd inputfiles = [] while True: file = input("Enter the name of an input…
Jump to turn (10)
- 1import pandas as pd inputfiles = [] while True: file = input("Enter the name of
- 2Inorder to select files would like to have a input window rather than asking one
- 3In Merged file the last Column "Date" value is coming as "C:/Users/Dell/Desktop/
- 4Again in above the .xtsx extention is coming. i just need the file name in date
- 5In the files there is a Column Name which has value delimited by "|". I need to
- 6In above merged file, Need a new column "Current" which is difference of "Debit"
- 7rename the column "Closing balance" to "Cumulative"
- 8Add new field "Name" to outputfile, value will be from another file named "Staff
- 9Traceback (most recent call last): File "c:\Users\Dell\Desktop\Desktop Files\ERP
- 10Traceback (most recent call last): File "c:\Users\Dell\Desktop\Desktop Files\ERP
- User
import pandas as pd
input_files = [] while True: file = input("Enter the name of an input file (or ‘done’ to finish): ") if file.lower() == ‘done’: break input_files.append(file)
Create an empty dataframe to store merged data
merged_df = pd.DataFrame()
Read and merge the input files
for file in input_files: df = pd.read_excel(file) df[‘Date’] = file merged_df = pd.concat([merged_df, df])
Write the merged dataframe to an output Excel file
output_file = ‘merged_data.xlsx’ merged_df.to_excel(output_file, index=False)
print(“Merged dataframe has been written to”, output_file)
- Assistant
The code above prompts the user to enter the names of input files, which are then read and merged into a single dataframe. The resulting merged dataframe is then written to an output Excel file.