You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the code works fine!
However I am a newbie and tried to make editing the training data a bit more easy so I've created a file training_data.data as:
Green,3,Apple
Yellow,3,Apple
Red,1,Grape
Red,1,Grape
Yellow,3,Lemon
and then import this with:
import pandas as pd
training_data = pd.read_csv('training_data.data', header=-1)
and now I gut the error TypeError: 'int' object is not subscriptable.
The text was updated successfully, but these errors were encountered:
also tried to force the dimension to be integer, but now get many weird errors:
training_data = pd.read_csv('training_data.data', dtype={"diameter": np.int32})
header = training_data.columns
The training_data.data is now:
"color","diameter","label"
'Green',3,'Apple'
'Yellow',3,Apple'
'Red',1,'Grape'
'Red',1,'Grape'
'Yellow',3,'Lemon'
Traceback (most recent call last):
File "/home/rpires/.local/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 2656, in get_loc
return self._engine.get_loc(key)
File "pandas/_libs/index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 1601, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 1608, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "decision_tree_withCSVdata.py", line 410, in
my_tree = build_tree(training_data)
File "decision_tree_withCSVdata.py", line 318, in build_tree
gain, question = find_best_split(rows)
File "decision_tree_withCSVdata.py", line 247, in find_best_split
n_features = len(rows[0]) - 1 # number of columns
File "/home/rpires/.local/lib/python3.7/site-packages/pandas/core/frame.py", line 2927, in getitem
indexer = self.columns.get_loc(key)
File "/home/rpires/.local/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 2658, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas/_libs/index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 1601, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 1608, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 0
the code works fine!
However I am a newbie and tried to make editing the training data a bit more easy so I've created a file training_data.data as:
Green,3,Apple
Yellow,3,Apple
Red,1,Grape
Red,1,Grape
Yellow,3,Lemon
and then import this with:
import pandas as pd
training_data = pd.read_csv('training_data.data', header=-1)
and now I gut the error TypeError: 'int' object is not subscriptable.
The text was updated successfully, but these errors were encountered: