You can do what you're asking like this:
import pandas as pd
temp = pd.DataFrame(columns=['Address', 'State', 'Zip', 'Status', 'Status', 'Date', 'Partner'],
data=[['xx','NY',110,'G','O',1,'V']])
print(temp)
temp.columns = [col + str(i) if col == "Status" else col for i, col in enumerate(temp.columns)]
temp = temp.drop(temp.columns[3], axis=1).rename(columns={col:"Status" for col in temp.columns if col.startswith("Status")})
print(temp)
Output:
Address State Zip Status Status Date Partner
0 xx NY 110 G O 1 V
Address State Zip Status Date Partner
0 xx NY 110 O 1 V
The temp.columns assignment appends a unique number to each column named Status, thereby ensuring there are no duplicate columns with that name. We then drop the column at the position you have in mind, and then restore the name of any remaining columns that start with Status to again be Status.
The full test code looks like this:
file="PSI 001.xlsx"
import pandas as pd
from openpyxl import load_workbook
dfs = pd.read_excel(file, sheet_name=None,skiprows=5)
output = dict()
for ws, df in dfs.items():
if ws.startswith("Cancelled"):
temp = df
temp.columns = [col + str(i) if col == "Status" else col for i, col in enumerate(temp.columns)]
temp = temp.drop(temp.columns[3], axis=1).rename(columns={col:"Status" for col in temp.columns if col.startswith("Status")})
output[ws] = temp
writer = pd.ExcelWriter(f'{file.replace(".xlsx","")} (updated headers).xlsx')
for ws, df in output.items():
df.to_excel(writer, index=None, sheet_name=ws)
writer.save()
writer.close()
I tested this with a file named PSI 001.xlsx and a sheet named Cancelled containing the following:
skip
skip
skip
skip
skip
Address State Zip Status Status Date Partner
xx NY 110 G O 1 V
... and it produced a filed named PSI 001 (updated headers) with a sheet named as above with the following contents:
Address State Zip Status Date Partner
xx NY 110 O 1 V