0
Prediction_final = np.argmax(results, axis=0)[0]
output = pd.DataFrame(Prediction_final.T)

The code above takes a numpy array, finds the argmax, and then converts it into a Pandas data frame for export. Unfortunately, a value error is raised when I do this:

Traceback (most recent call last):
  File "svm_own.py", line 106, in <module>
    output = pd.DataFrame(Prediction_final.T)
  File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py", line 404, in __init__
raise ValueError('DataFrame constructor not properly called!')

ValueError: DataFrame constructor not properly called!

I've been trying to debug this, but have not found why this error occurs. Any thoughts?

Gabby Newell
  • 123
  • 1
  • 5
  • You'll get that error if you try to give `DataFrame` a single number, which it looks like you are doing. – user3483203 May 30 '18 at 17:21
  • np.argmax returns a single value, not an array, which is not a valid object to pass to the DataFrame constructor. I don't really understand what your goal is. Could you post the nature of `results` and your desired output? – ChootsMagoots May 30 '18 at 17:21
  • 2
    If you really want a df with only 1 cell then just wrap with `[]` :`pd.DataFrame([Prediction_final.T])` – rafaelc May 30 '18 at 17:30
  • if your goal is to then write that single value to a file, then just follow [these instructions](https://stackoverflow.com/questions/6159900/correct-way-to-write-line-to-file?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) instead of using `df.to_csv()` – ChootsMagoots May 30 '18 at 17:32
  • Looks like the [0] was the issue. I wanted all the values, an accidentally took a single value. Thanks for the solution. @chrisz your answer worked, If you post it as a solution, I'll accept it. – Gabby Newell May 30 '18 at 19:43

0 Answers0