0

I am trying out Create ML for the first time and I am trying to use a CSV file. Problem is that the CSV column for the target is a float type. It only accepts int or string. So, I used pandas to convert the column to a string with:

df.pris_yrs = df.pris_yrs.astype(str)

# I have also tried

df.pris_yrs = df.pris_yrs.apply(str)

Checking the dtype of the dataframe returns an object which is also a string in Pandas, but Create ML still is having the same error.

Question: How do I get an a dataframe object to work as the target in Create ML?

1 Answers1

0

To transform one column of a dataframe to int I recommend you:

df["pris_yrs "]=df["pris_yrs "].astype(int)

For every ML model you should use numerical targets (even if you have a categorical feature, you can transform it easily labelling it).

You obtain an error probably because your ML model don't support a string as a target.

Alex Serra Marrugat
  • 1,849
  • 1
  • 4
  • 14
  • The problem with that solution would be it would completely wreck the data making it not the same. I guess the better question would be how can I use a pandas object in Create ML? –  Dec 30 '20 at 21:14
  • You have an strange situation, why you want to change int to string? Which ML algorithm are you using? – Alex Serra Marrugat Jan 02 '21 at 10:39
  • I believe I have found a way to do it with the quoting parameter for to_csv in pandas. Docs specifically say that this should be used when you have floating point numbers. –  Jan 02 '21 at 19:32