I am trying to understand how i can add to my current script where im able to make changes at sheet level. I want to update names of columns and map them to new names. For example, if a column is called 'locationname' i want to update the column name for all sheets within the file as 'company name'
My code so far where I have managed to delete a specific sheet from a file-
import pandas as pd
from openpyxl import load_workbook
for file in os.listdir("C:/Users/yam/Desktop/hhh/python/sterls"):
if file.startswith("TVC"):
wb = load_workbook(file)
if 'Opt-Ins' in wb.sheetnames:
wb.remove(wb['Opt-Ins'])
wb.save(file)
I want to apply the below to all sheets within the file for my script above-
column_name_update_map = {'Company Name': 'LocationName', 'Address': 'StreetAddress','City':'City','State':'State','Zip':'Zip','Phone Number':'GeneralPhone','Email':'GeneralEmail'}
df = df.rename(columns=column_name_update_map)
How do I implement this within my loop and save to file?