I am trying to use Pandas
to display a dictionary
import pandas as pd
I am getting the error message
ValueError: If using all scalar values, you must pass an index
My dictionary looks like this
{0: "Classifier: SVC(kernel='linear') Time: 6.324216842651367", 1: "Classifier: SVC(kernel='poly') Time: 6.96935248374939", 2: "Classifier: SVC(kernel='sigmoid') Time: 12.137079954147339"}
I think I have found out what the error is. I need to change the data and pass indeces. But I am not sure how to do this, as my dictionary is created in a loop like this:
for x in range(len(arrL)):
....
dictionary[x] = "Classifier: "+str(arrL[x]) + " Time: " + str(times[x])
pd.DataFrame(dictionary)
If I should/can somehow remove the indeces/numbers to help the problem, that would be find, unless a better solution is adviced
The code that gives me the error is:
pd.DataFrame(dictionary)
---------------------------------Update-----------------------------------
Another problem is that I need something similar to .append() or += to the dictionary
for x in range(len(objList)):
arrL[x].fit(X_train, c_train)
...
dictionary = {
"Classifier": arrL[x],
"Time": times[x],
}
Notice this approach is different from the original way I created the dictionary:
dictionary[x] = "Classifier: " + os.linesep +str(objList[x]) + " Time: " + str(times[x])
I need to add all the objects to the dictionary. Right now they are just been overwritten as the loop continues, and at the end only the last object from the list is in the dictionary. I need something like dictionary += ..