# How to handle variables with text and number?

This is a post with two related questions in one.

The first question is:

What is the correct procedure when I have variables with different kind of information? Imagine you have a column which has been filled with numbers and text (there were not any policies or validations on how to fill the field), so I have a column such as "number of rooms in the household" with:

A = [1,2,3,"in excellent condition"]

Which is the correct way to handle this? I have thought that the correct way is to separate into two variables A_text and A_number where:

A_text = [NA,NA,NA,"in excellent condition"]
A_number = [1,2,3,NA]


And then work with them according to the case. With text do the corresponding text mining analysis and with the numbers do the corresponding numerical treatments.

The second related question is how to do this in python, I will share how I would do it in MATLAB, hoping to have your help on how to do it with python.

In general, this second question is about how to do a loop when some cases don't work.

Table.Variable_numeric = zeros(height(Table),1)
for i=1:height(Table)
try
Table.Variable_numeric(i) = str2num(Table.Variable(i));
catch
Table.Variable_numeric(i) = nan;
end
end