在 Jupyter Notebook 中使用 Python 3.x
将 pandas 导入为 pd 并将 numpy 导入为 np 后,我有一个 df 数据框,其中有一个“价格”列,我想使用 np.linspace() 如下:
bins = np.linspace(min(df["Price"]), max(df["Price"]), 3)
我收到以下错误:
---------------------------------------------------------------------------
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')