I have a csv file with more than a million rows. I made that into a dataframe 'csv1'. I have to update every elements of a specific column depending upon some condition. For example if the column contains a string like : "New Account" , then I have to replace it with "NEW", if the column contains 'Current Account" I have to replace with '0'. Similarly I have to replace 'Closed Account':'CLSD' etc. I have used a dict 'mmap' to map the strings and change it accordingly.
But the problem is updating the column values is taking too long time. Is there a better and fast way to do this?
The code I used:
mmap={'Current Account':'0','New Account':'NEW','Closed Account':'CLSD'}
csv1=pd.read_csv("csv_file.csv")
else_str='+01'
for index,row in csv1.iterrows():
status=csv1.loc[index,"ColumnName"]
if status in mmap:
csv1.loc[index,"ColumnName"]=mmap[status]
else:
csv1.loc[index,"ColumnName"]=else_str