TypeError Traceback (most recent call last) Cell In[15], line 3 1 import matplotlib.pyplot as plt 2 bins = [0, 1000, 5000, 10000, 50000, 100000, 200000, 500000, 1000000, 5000000] ----> 3 plt.hist(latest_data,bins,histtpye = 'bar',rwidth = 0.88) 4 plt.xlabel('Country/Region') 5 plt,ylabel('Amount') File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\pyplot.py:2645, in hist(x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, data, **kwargs) 2639 @_copy_docstring_and_deprecators(Axes.hist) 2640 def hist( 2641 x, bins=None, range=None, density=False, weights=None, 2642 cumulative=False, bottom=None, histtype='bar', align='mid', 2643 orientation='vertical', rwidth=None, log=False, color=None, 2644 label=None, stacked=False, *, data=None, **kwargs): -> 2645 return gca().hist( 2646 x, bins=bins, range=range, density=density, weights=weights, 2647 cumulative=cumulative, bottom=bottom, histtype=histtype, 2648 align=align, orientation=orientation, rwidth=rwidth, log=log, 2649 color=color, label=label, stacked=stacked, 2650 **({"data": data} if data is not None else {}), **kwargs) File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\__init__.py:1459, in _preprocess_data.<locals>.inner(ax, data, *args, **kwargs) 1456 @functools.wraps(func) 1457 def inner(ax, *args, data=None, **kwargs): 1458 if data is None: -> 1459 return func(ax, *map(sanitize_sequence, args), **kwargs) 1461 bound = new_sig.bind(ax, *args, **kwargs) 1462 auto_label = (bound.arguments.get(label_namer) 1463 or bound.kwargs.get(label_namer)) File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\axes\_axes.py:6762, in Axes.hist(self, x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs) 6758 for xi in x: 6759 if len(xi): 6760 # python's min/max ignore nan, 6761 # np.minnan returns nan for all nan input -> 6762 xmin = min(xmin, np.nanmin(xi)) 6763 xmax = max(xmax, np.nanmax(xi)) 6764 if xmin <= xmax: # Only happens if we have seen a finite value. TypeError: '<' not supported between instances of 'pandas._libs.interval.Interval' and 'float'
时间: 2023-12-16 16:03:13 浏览: 146
【bug解决】TypeError: Data location must be “memory” for parameter in function, but none was given.
这个错误是由于您尝试使用不同类型的对象进行比较而引起的。在这种情况下,您正在尝试将一个 pandas._libs.interval.Interval 对象与一个 float 对象进行比较,这是不被允许的。
这个错误是由于您在使用 Matplotlib 的 hist() 函数时,传递了一个错误类型的对象。您需要检查您的代码,并确保您传递给 hist() 函数的对象是 NumPy 数组或 Pandas Series,而不是 Pandas Interval 对象。
如果您的数据集包含 Interval 对象,您可以使用 Pandas 的 .mid 属性来获取 Interval 对象的中点值,然后将这些值传递给 hist() 函数。例如:
```
import matplotlib.pyplot as plt
import pandas as pd
# 假设您的数据在一个名为 df 的 Pandas DataFrame 中,其中有一个名为 'values' 的列包含 Interval 对象
values = df['values'].mid
# 将中点值传递给 hist() 函数
plt.hist(values, bins=10)
plt.show()
```
这应该可以解决您的问题。如果您需要进一步的帮助,请提供更多的上下文和代码示例。
阅读全文