0

I am using .astype(int) to update my column and it works well. I just found out that there will be cases where I will have a string value do I have to conditionally change the type of the column.

The logic is:

if ['element_name'] != 'o' then 

     df['element_value'] = df['element_value'].astype(int) 

The column will be empty when I do this so I don't have to worry about what is in the column already.

I have tried things like:

df[df(['element_name'] != 'o'])['element_value'].astype(int)] 

but couldn't get it to work.

The other questions were showing how to change type to numeric and I already know hot to do that as I think I put in my question. They showed how to check if a columns type and how to force to another type. What I need to change the a column type to numeric based on the value in another column. In particular, If a different column is not equal to a value, then change the first column to numeric. Thanks.

So can you tell me where the question is that answers mhy question? I can't find it. There is no questions that I can find that tells you how to update the type of a column, based on the value o another column. If I am missing it, please let me know. I just want my question answerd.

0 Answers0