Apr-12-2023, 05:14 PM
This code for converting the values to numeric is also removing characters, I believe.
Can someone advise on how to alter it so it keeps the characters, except for the first line of code that removes the last '0;, that can stay as is. Thank you.
Here is the Before and After values, something in the code has caused Mic/Result to drop most of the values in the new MIC column:
Mic/Result: MIC:
0.125 NaN
0.125 NaN
<=0.03125 0.03125
0.125 NaN
0.125 NaN
# Remove 0 at the end for MIC/RESULT .
results_df['MIC/RESULT']=np.where(results_df['WHO CODE']=='LMU', results_df['MIC/RESULT'].str.rstrip('.0'),results_df['MIC/RESULT'])
#Convert MIC/RESULT to numeric
results_df['MIC']=np.where(results_df['WHO CODE']=='LMU',results_df['MIC/RESULT'].str.split(' ').str[1],results_df['MIC/RESULT'].replace(' ',''))
results_df['MIC']=pd.to_numeric(results_df['MIC'])
Can someone advise on how to alter it so it keeps the characters, except for the first line of code that removes the last '0;, that can stay as is. Thank you.
Here is the Before and After values, something in the code has caused Mic/Result to drop most of the values in the new MIC column:
Mic/Result: MIC:
0.125 NaN
0.125 NaN
<=0.03125 0.03125
0.125 NaN
0.125 NaN
# Remove 0 at the end for MIC/RESULT .
results_df['MIC/RESULT']=np.where(results_df['WHO CODE']=='LMU', results_df['MIC/RESULT'].str.rstrip('.0'),results_df['MIC/RESULT'])
#Convert MIC/RESULT to numeric
results_df['MIC']=np.where(results_df['WHO CODE']=='LMU',results_df['MIC/RESULT'].str.split(' ').str[1],results_df['MIC/RESULT'].replace(' ',''))
results_df['MIC']=pd.to_numeric(results_df['MIC'])
buran write Apr-12-2023, 06:37 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.