0

Using Python 3.x in Jupyter Notebook

After importing pandas as pd and numpy as np I have a df dataframe, which has a "Price" column, I want to use np.linspace() as follows:

bins = np.linspace(min(df["Price"]), max(df["Price"]), 3)

and i get the following error:

---------------------------------------------------------------------------
UFuncTypeError                            Traceback (most recent call last)
<ipython-input-57-a109ed9a4033> in <module>
      7 #numpy.linspace(valor-inicial, valor-final, número de valores)
      8 #https://www.interactivechaos.com/manual/tutorial-de-numpy/las-funciones-linspace-y-logspace
----> 9 bins = np.linspace(min(df["Precio"]), max(df["Precio"]), 3)
     10 
     11 #Creamos una lista "group_names" que contiene los diferentes nombres de bin

<__array_function__ internals> in linspace(*args, **kwargs)

~\anaconda3\lib\site-packages\numpy\core\function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
    127     # Convert float/complex array scalars to float, gh-3504
    128     # and make sure one can use variables that have an __array_interface__, gh-6634
--> 129     start = asanyarray(start) * 1.0
    130     stop  = asanyarray(stop)  * 1.0
    131 

UFuncTypeError: ufunc 'multiply' did not contain a loop with signature 
matching types (dtype('<U32'), dtype('<U32')) -> dtype('<U32')
hpaulj
  • 221,503
  • 14
  • 230
  • 353
app
  • 21
  • 1
  • 1
    It sounds like your Price column contains strings, rather than numbers. – user2357112 Apr 02 '20 at 00:41
  • Show us a sample of the `df`, or at least the `Price` column. Look at the `min(df['Price']`. Does that make sense as a numeric range point? The error says it's a string, not a number. – hpaulj Apr 02 '20 at 07:01
  • The problem was solved thanks friends ... it happened that the Price column is of type "object", so with function df ["Price"] = df ["Price"]. astype ("int64") I converted it to int64 Thanks a lot – app Apr 03 '20 at 00:38

0 Answers0