x = (long list of data)
mymap = map(int, x.split())
box = []
mylist = list(mymap)
while len(mylist)>0:
box.append([str(mylist[1])]*mylist[0])
mylist = mylist[2:]
box.sort()
print(type(box))
type(box)
p=sns.displot(data = box)
p.set(xlabel = "Waiting time", ylabel = "Eruptions")这是我的代码,用于在sage中从非常长的数据列表中创建直方图。数据都是像"3600 79 280058“这样的值,然后是频率。除了直方图生成本身之外,一切都运行得很好。我已经尝试过输出列表,它打印得非常好。这是我运行它时的输出:
<class 'list'>
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-26-87f016146a7f> in <module>
9 print(type(box))
10 type(box)
---> 11 p=sns.displot(data = box)
12 p.set(xlabel = "Waiting time", ylabel = "Eruptions")
/usr/local/lib/python3.8/dist-packages/seaborn/distributions.py in displot(data, x, y, hue, row, col, weights, kind, rug, rug_kws, log_scale, legend, palette, hue_order, hue_norm, color, col_wrap, row_order, col_order, height, aspect, facet_kws, **kwargs)
2225
2226 _assign_default_kwargs(hist_kws, p.plot_univariate_histogram, histplot)
-> 2227 p.plot_univariate_histogram(**hist_kws)
2228
2229 else:
/usr/local/lib/python3.8/dist-packages/seaborn/distributions.py in plot_univariate_histogram(self, multiple, element, fill, common_norm, common_bins, shrink, kde, kde_kws, color, legend, line_kws, estimate_kws, **plot_kws)
422
423 # First pass through the data to compute the histograms
--> 424 for sub_vars, sub_data in self.iter_data("hue", from_comp_data=True):
425
426 # Prepare the relevant data
/usr/local/lib/python3.8/dist-packages/seaborn/_core.py in iter_data(self, grouping_vars, reverse, from_comp_data)
994 grouping_keys.append(self.var_levels.get(var, []))
995
--> 996 iter_keys = itertools.product(*grouping_keys)
997 if reverse:
998 iter_keys = reversed(list(iter_keys))
TypeError: 'NoneType' object is not iterable显然box是一个列表,因为type(box)返回list,那么我在这里遗漏了什么?是什么让它的类型变成了none?
发布于 2021-04-18 08:30:54
使用for使用while的实例,如下所示
x = (long list of data)
mymap = map(int, x.split())
box = []
mylist = list(mymap)
for i in range (len(mylist)):
box.insert(i, str(mylist[1] *mylist[0]) # or append
mylist = mylist[2:]
box.sort()
print(type(box))
type(box)
p=sns.displot(data = box)
p.set(xlabel = "Waiting time", ylabel = "Eruptions")https://stackoverflow.com/questions/67144033
复制相似问题