I have the following code to replace text in my dataframe - dfMSR.
oldtxts = ['NA', 'na']
newtxt = 'N/A'
for oldtxt in oldtxts:
if oldtxt in dfMSR.values:
dfMSR = dfMSR.replace(oldtxt, newtxt, regex=True)
else:
print("\nNo {oldtxt} in Dataframe")
Is there a better way to replace all cases scenarios without spelling them out or changing the case of all text in the dataframe to upper or lower? In the above code if the user wrote 'Na', it wouldn't be replaced as I haven't included it in oldtxts.
edit: sample data and desired output added
dfMSR = pd.DataFrame({'A':['NA','na','O', '', 'N/A'],
'B':['Anna','E','NA', 'Z', 'Na']})
desired output:
A B
0 N/A Anna
1 N/A E
2 O N/A
3 Z
4 N/A N/A
Thanks