Message Boards Message Boards

0
|
3111 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

How to convert character variables to numeric variables in a data set?

Posted 2 years ago

Hi everyone.
I have this list of data.
I would like to replace each of the characters to numeric variables.
I would like to create numeric variables between 0 and 1 just like python does with the getdummies statement. https://pandas.pydata.org/docs/reference/api/pandas.get_dummies.html
Does anyone know how I can do it in Mathematica ?
Is there a function similar to get
dummies() in the Wolfram language that does the same thing for me?
the data is attached in the file NewData.csv

nuevo = Import["NewData.csv"];
  Shallow[nuevo]
Attachments:
4 Replies
checkingstatus1 = 
  Flatten[NewData2[[All, 
     1]] /. {{"A11" -> 1, "A12" -> 0, "A13" -> 0, "A14" -> 0}}];
checkingstatus2 = 
  Flatten[NewData2[[All, 
     1]] /. {{"A11" -> 0, "A12" -> 1, "A13" -> 0, "A14" -> 0}}];
checkingstatus3 = 
  Flatten[NewData2[[All, 
     1]] /. {{"A11" -> 0, "A12" -> 0, "A13" -> 1, "A14" -> 0}}];
checkingstatus4 = 
  Flatten[NewData2[[All, 
     1]] /. {{"A11" -> 0, "A12" -> 0, "A13" -> 0, "A14" -> 1}}];

This is the example, I was able to solve it, thanks, or if you have another way to solve it, I would like to know it

Posted 2 years ago

Hi Luis,

I don't think there is a built-in function to do that, however, one-hot encoding is easy to implement. Take a look at this implementation.

If you want a mapping to unique integer values, take a look at ArrayComponents.

POSTED BY: Rohit Namjoshi
Posted 2 years ago

Can you give an example of what conversion you want? Maybe you can manually put together a short example that illustrates what the result would be of processing your csv file.

POSTED BY: Eric Rimbey
checkingstatus1 = 
  Flatten[NewData2[[All, 
     1]] /. {{"A11" -> 1, "A12" -> 0, "A13" -> 0, "A14" -> 0}}];
checkingstatus2 = 
  Flatten[NewData2[[All, 
     1]] /. {{"A11" -> 0, "A12" -> 1, "A13" -> 0, "A14" -> 0}}];
checkingstatus3 = 
  Flatten[NewData2[[All, 
     1]] /. {{"A11" -> 0, "A12" -> 0, "A13" -> 1, "A14" -> 0}}];
checkingstatus4 = 
  Flatten[NewData2[[All, 
     1]] /. {{"A11" -> 0, "A12" -> 0, "A13" -> 0, "A14" -> 1}}];

This is the example, I was able to solve it, thanks, or if you have another way to solve it, I would like to know it

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract