I have a excel table as :
ABC 01th,02th,03th,04th BCD 26th,02th CVF 01th
Expected output ABC 01st,02nd,03rd,04th BCD 26th,02nd CVF 01st
I have tried this code but it is replacing if only that single value is present in cell. I need to repalce all the wrong values in cell with new values. Can anyone help with this.
from xlrd import open_workbook
import xlsxwriter
rb = open_workbook("Dates.xlsx")
wb = xlsxwriter.Workbook('Updated_Workbook1.xlsx')
ws = wb.add_worksheet()
s_orig = rb.sheet_by_index(0)
NEW_Values= {'01th': '01st',
'02th': '02nd',
'03th': '03rd',
'21th': '21st',
'22th':'22nd',
'23th':'23rd',
'31th':'31st'}
for row in range(s_orig.nrows):
for col in range(s_orig.ncols):
if s_orig.cell(row,col).value in NEW_Values:
# s.write(row, col, NEW_Values[item])
ws.write(row, col, NEW_Values[s_orig.cell(row,col).value])
else:
ws.write(row, col, s_orig.cell(row,col).value)
wb.close()