last day (15 days later) » 

2:52 AM
2
A: I have a table with more than 100 columns, some of the columns have string value which I want to change to numeric value

WeNYoBenUsing to_numeric with errors='coerce' , then fillna in your case you want the fill number as 1 , after that combine_first df2=df2.select_dtypes(include = ['object']).apply(pd.to_numeric,errors='coerce')\ .fillna(1).combine_first(df2) subdf2=df2.select_dtypes(include = ['object']) f...

 
Wow. Thank you very much :), its very nice you. This is my second time on stack overflow, I received support better than books. You guys are best. I really appreciate it
Just wondering, is there maybe a for loop approach to answering this ?.
 
@krijan it can be , but apply is another layout of for loop , so they just almost the same, I will update
 
please update me with it :) I really appreciate it. Thank you
 
@krijan already updated :-)
 
Hello, i am getting some KeyError : 'x', is it possible to know what the issue is ?
 
2:52 AM
@krijan sorty that should be x not 'x' updated
 
@WeNYoBen Hello, Thank you for your reply, running the code through for loop method, it didnt manage to change my values to numeric. I tried subdf2.info(), and i saw that the code actually changed all of my float 64 columns to object. So technically it change all my columns to object hahah
Is there some error :)?
 
ummmm
did you check dtype of df2 ?
after running the code ?
subdf2=df2.select_dtypes(include = ['object'])
for x in list(subdf2):

df2[x]=pd.to_numeric(df2[x],errors='coerce').fillna(0)
 
3:34 AM
i checked the dtype for subdf2
i had to check for df2, i see i was checking subdf2
Thank you very much for your assistance :)
 

last day (15 days later) »