Guided project-Exploring eBay car sales data

Screen Link: https://app.dataquest.io/m/294/guided-project%3A-exploring-ebay-car-sales-data/3/initial-exploration-and-cleaning

Your Code: autos["odometer_km"] = autos["odometer_km"].astype(int) autos["price"] = autos["price"].astype(int)

What I expected to happen: Convert values of the price and odometer metter column to intergers

What actually happened: ```ValueError: invalid literal for int() with base 10: ‘150,000’``

Other details: ValueErrorTraceback (most recent call last)
in ()
----> 1 autos[“odometer_km”] = autos[“odometer_km”].astype(int)
2 autos[“price”] = autos[“price”].astype(int)

/dataquest/system/env/python3/lib/python3.4/site-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs)
116 else:
117 kwargs[new_arg_name] = new_arg_value
–> 118 return func(*args, **kwargs)
119 return wrapper
120 return _deprecate_kwarg

/dataquest/system/env/python3/lib/python3.4/site-packages/pandas/core/generic.py in astype(self, dtype, copy, errors, **kwargs)
4002 # else, only a single dtype is given
4003 new_data = self._data.astype(dtype=dtype, copy=copy, errors=errors,
-> 4004 **kwargs)
4005 return self._constructor(new_data).finalize(self)
4006

/dataquest/system/env/python3/lib/python3.4/site-packages/pandas/core/internals.py in astype(self, dtype, **kwargs)
3460
3461 def astype(self, dtype, **kwargs):
-> 3462 return self.apply(‘astype’, dtype=dtype, **kwargs)
3463
3464 def convert(self, **kwargs):

/dataquest/system/env/python3/lib/python3.4/site-packages/pandas/core/internals.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)
3327
3328 kwargs[‘mgr’] = self
-> 3329 applied = getattr(b, f)(**kwargs)
3330 result_blocks = _extend_blocks(applied, result_blocks)
3331

/dataquest/system/env/python3/lib/python3.4/site-packages/pandas/core/internals.py in astype(self, dtype, copy, errors, values, **kwargs)
542 def astype(self, dtype, copy=False, errors=‘raise’, values=None, **kwargs):
543 return self._astype(dtype, copy=copy, errors=errors, values=values,
–> 544 **kwargs)
545
546 def _astype(self, dtype, copy=False, errors=‘raise’, values=None,

/dataquest/system/env/python3/lib/python3.4/site-packages/pandas/core/internals.py in _astype(self, dtype, copy, errors, values, klass, mgr, **kwargs)
623
624 # _astype_nansafe works fine with 1-d only
–> 625 values = astype_nansafe(values.ravel(), dtype, copy=True)
626 values = values.reshape(self.shape)
627

/dataquest/system/env/python3/lib/python3.4/site-packages/pandas/core/dtypes/cast.py in astype_nansafe(arr, dtype, copy)
690 elif arr.dtype == np.object_ and np.issubdtype(dtype.type, np.integer):
691 # work around NumPy brokenness, #1987
–> 692 return lib.astype_intsafe(arr.ravel(), dtype).reshape(arr.shape)
693
694 if dtype.name in (“datetime64”, “timedelta64”):

pandas/_libs/lib.pyx in pandas._libs.lib.astype_intsafe()

pandas/_libs/src/util.pxd in util.set_value_at_unsafe()

1 Like

Hi @sntohsi17. The key to this error message is this part: ValueError: invalid literal for int() with base 10: '150,000'. The int() function is unable to convert '150,000' to an integer because it contains the comma. (You’ll probably want to check the price column as well to make sure there aren’t any nonnumeric characters, and then it should work as expected.)

1 Like

Thank you so much that works perfectly.