I have this code:
for row in range(len(df[col])):
df[col][row] = int(df[col][row].replace(',',''))
df[col] = df[col].astype(int)
df[col] = np.round(df[col]/500)*500 #rounds the numbers to the closest 500 multiple.
df[col] = df[col].astype(int) #round returns a float, this turns it back to int after rounding
In the for loop the: df[col][row].replace(',','') basically removes commas from numbers that are stored as objects like 1,430 and then converts it to int like 1430
Then I'm having to add the df[col] = df[col].astype(int) because otherwise, the following np.round() throws the error: 'float' object has no attribute 'rint'
The thing is that after the np.round() I'm having to add again the .astype(int) because the round as I have it is returning a float, but I want ints.
I'm seeing that the execution of this is considerably long, even thought my dataframe is only 32 x 17
is there anyway I could improve it??