Skip to content

TypeError in chapter 3 with python 3.7 #4

Description

@rrcook

MacOS 10.14 Mojave, python 3.7.
The cell

#cat_to_num(data['Sex'])
features = prepare_data(data_train)
features[:5]

Gives

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-1224e570c6ab> in <module>
      1 #cat_to_num(data['Sex'])
----> 2 features = prepare_data(data_train)
      3 features[:5]

<ipython-input-5-07c5dd9cc834> in prepare_data(data)
     16 
     17     # Adding Embarked categorical value
---> 18     features = features.join( cat_to_num(data['Embarked']) )
     19 
     20     return features

<ipython-input-4-a227bdfcf37c> in cat_to_num(data)
      2 # Changed to automatically add column names
      3 def cat_to_num(data):
----> 4     categories = unique(data)
      5     features = {}
      6     for cat in categories:

/usr/local/lib/python3.7/site-packages/numpy/lib/arraysetops.py in unique(ar, return_index, return_inverse, return_counts, axis)
    262     ar = np.asanyarray(ar)
    263     if axis is None:
--> 264         ret = _unique1d(ar, return_index, return_inverse, return_counts)
    265         return _unpack_tuple(ret)
    266 

/usr/local/lib/python3.7/site-packages/numpy/lib/arraysetops.py in _unique1d(ar, return_index, return_inverse, return_counts)
    310         aux = ar[perm]
    311     else:
--> 312         ar.sort()
    313         aux = ar
    314     mask = np.empty(aux.shape, dtype=np.bool_)

TypeError: '<' not supported between instances of 'float' and 'str'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions