我是Python的新手,我试图将整数列除以字典中的键数。我在分母上添加了+ 1以避免除以0,但我仍然得到了ZeroDivisionError。
感谢任何帮助。谢谢!
代码:
Questions_not_Duplicate_v2['bigram_match_frac'] = Questions_not_Duplicate_v2.apply(lambda x: (x['bigram_match']*1.0)/(len(set(x['bi_gram_1'].keys()))+1))
Questions_not_Duplicate_v2['bigram_match_frac'].show()
错误:
RuntimeError Traceback (most recent call last)
<ipython-input-73-4e14321362d6> in <module>()
----> 1 Questions_not_Duplicate_v2['bigram_match_frac'].show()
C:\Users\rakesh\Anaconda2\lib\site-packages\graphlab\data_structures\sarray.pyc in show(self, view)
2853 """
2854 from ..visualization.show import show
-> 2855 show(self, view=view)
2856
2857 def item_length(self):
C:\Users\rakesh\Anaconda2\lib\site-packages\multipledispatch\dispatcher.pyc in __call__(self, *args, **kwargs)
162 self._cache[types] = func
163 try:
--> 164 return func(*args, **kwargs)
165
166 except MDNotImplementedError:
C:\Users\rakesh\Anaconda2\lib\site-packages\graphlab\canvas\glc_display_dispatch.pyc in show(obj, **kwargs)
19
20 graphlab.canvas.inspect.find_vars(obj)
---> 21 return graphlab.canvas.show(graphlab.canvas.views.sarray.SArrayView(obj, params=kwargs))
22
23
C:\Users\rakesh\Anaconda2\lib\site-packages\graphlab\canvas\utils.pyc in show(variable)
129 get_target().state.set_selected_variable(variable)
130 variable.validate_js_component_name(variable.get_js_component())
--> 131 return get_target().show()
132
133 def _get_id(ref):
C:\Users\rakesh\Anaconda2\lib\site-packages\graphlab\canvas\target.pyc in show(self, variable)
169 'ipython': True,
170 }
--> 171 data.update(view.get_staticdata())
172
173 import IPython
C:\Users\rakesh\Anaconda2\lib\site-packages\graphlab\canvas\views\sarray.pyc in get_staticdata(self)
67 }
68 return {
---> 69 'sketch': self.get_sketch(background=False),
70 'histogram': self.__get_histogram_static()
71 }
C:\Users\rakesh\Anaconda2\lib\site-packages\graphlab\canvas\views\sarray.pyc in get_sketch(self, background, cached_only)
297 else:
298 if self.__cached_sketch is None:
--> 299 self.__cached_sketch = sa.sketch_summary(background=background)
300 sk = self.__cached_sketch
301 if issubclass(sa.dtype(), dict):
C:\Users\rakesh\Anaconda2\lib\site-packages\graphlab\data_structures\sarray.pyc in sketch_summary(self, background, sub_sketch_keys)
2742 sub_sketch_keys = list()
2743
-> 2744 return Sketch(self, background, sub_sketch_keys = sub_sketch_keys)
2745
2746 def append(self, other):
C:\Users\rakesh\Anaconda2\lib\site-packages\graphlab\data_structures\sketch.pyc in __init__(self, array, background, sub_sketch_keys, _proxy)
170 raise TypeError("Sketch object can only be constructed from SArrays")
171
--> 172 self.__proxy__.construct_from_sarray(array.__proxy__, background, sub_sketch_keys)
173
174 def __repr__(self):
graphlab\cython\cy_sketch.pyx in
graphlab.cython.cy_sketch.UnitySketchProxy.construct_from_sarray()
graphlab\cython\cy_sketch.pyx in
graphlab.cython.cy_sketch.UnitySketchProxy.construct_from_sarray()
RuntimeError: Runtime Exception. Exception in python callback function evaluation:
ZeroDivisionError('float division by zero',):
Traceback (most recent call last):
File "graphlab\cython\cy_pylambda_workers.pyx", line 450, in graphlab.cython.cy_pylambda_workers._eval_lambda_by_sframe_rows
File "graphlab\cython\cy_pylambda_workers.pyx", line 221, in graphlab.cython.cy_pylambda_workers.lambda_evaluator.eval_sframe_rows
File "<ipython-input-61-c7d77added1c>", line 3, in <lambda>
ZeroDivisionError: float division by zero
该错误似乎与Python 2.7 - GraphLab : ZeroDivisionError: float division by zero非常相似,但我无法弄明白。