I am trying to extract and combine selected columns from 19 Excel files into single excel file. Am able to extract required columns from single file with below code.
import pandas as pd
import openpyxl
file = pd.read_excel("Shift Handover To A - 05-25-2021.xlsx", "25th May")
dataframe=pd.DataFrame(file[["S No", "Issue Reported By", "Shift", "Severity", "ServiceDesk Ticket #", "Issue Description", "Issue Type", "System Component", "Server Type", "Date and Time of the occurrence", "DT Observed", "Action Taken", "Worked By", "DT Action Taken", "Date and Time Resolution", "Current Stus"]])
# selecting rows based on condition
rslt_df = dataframe.loc[dataframe['Current Stus'] == 'In-Progress' ]
rslt_df.to_excel('output.xlsx')
Am trying to apply it for all files with below code,
import os
import pandas as pd
cwd = os.path.abspath('')
import openpyxl
files = os.listdir(cwd)
for file in files:
if file.startswith('Shift'):
file = pd.read_excel(os.path.join(cwd, file))
dataframe=pd.DataFrame(file[["S No", "Issue Reported By", "Shift", "Severity", "ServiceDesk Ticket #", "Issue Description", "Issue Type", "System Component", "Server Type", "Date and Time of the occurrence", "DT Observed", "Action Taken", "Worked By", "DT Action Taken", "Date and Time Resolution", "Current Stus"]])
# selecting rows based on condition
rslt_df = dataframe.loc[dataframe['Current Stus'] == 'In-Progress' ]
#print(rslt_df)
rslt_df.to_excel('output.xlsx')
But am receiving TypeError for dataframe=pd.DataFrame(file..... "TypeError: string indices must be integers" What could be wrong?
read_excelitself will produce a dataframe, no need to convert it to adfagain