2016-08-08 23 views
6

JSONではありません私は(前年比)は、この議論に出くわした:https://github.com/bokeh/bokeh/issues/2392ボケ:ValueErrorを:範囲のfloat値のうちに準拠

私はまた、任意のerrors..andせずに白い画面を見て、私は撮ってみました

パンダは空のデータが入っている行もたくさん取得しているので、私はdropnaを試しました。これは全くデータがないという結果に終わりました。だからではなく、私はちょうど

import pandas as pd 
from bokeh.plotting import figure, output_file, show 

df = pd.read_excel(path,sheetname,parse_cols="A:B") 
df = df.head(n=19) 
print(df) 
rtngs = ['iAAA','iAA+','iAA','iAA-','iA+','iA','iA-','iBBB+','iBBB','iBBB-','iBB+','iBB','iBB-','iB+','iB','iB-','NR','iCCC+'] 
x= df['Score'] 
output_file("line.html") 

p = figure(plot_width=400, plot_height=400, x_range=(0,100),y_range=rtngs) 

# add a circle renderer with a size, color, and alpha 
p.circle(df['Score'], df['Rating'], size=20, color="navy", alpha=0.5) 

# show the results 
#output_notebook() 
show(p) 

DF DF(したがってdf = df.head(n=19)ライン)に行くべき行指定:上記

Rating Score 
0 iAAA 64.0 
1 iAA+ 33.0 
2  iAA 7.0 
3 iAA- 28.0 
4  iA+ 36.0 
5  iA 62.0 
6  iA- 99.0 
7 iBBB+ 10.0 
8 iBBB 93.0 
9 iBBB- 91.0 
10 iBB+ 79.0 
11 iBB 19.0 
12 iBB- 95.0 
13 iB+ 26.0 
14  iB 9.0 
15 iB- 26.0 
16  NR 49.0 
17 iCCC+ 51.0 
18 iAAA 18.0 

は私のノートブック内の出力を示しているが、それでもスロー: ValueError: Out of range float values are not JSON compliant

また、出力ファイルも生成しません(したがって?)。この小さなサブセットでこのエラーを取り除くにはどうすればよいですか?それはNaN値に関連していますか?大規模なデータセットの「死の白いスクリーン」問題も解決するでしょうか?

ありがとうございました。

あなたが全体のエラーを見たい場合:

--------------------------------------------------------------------------- 
ValueError        Traceback (most recent call last) 
<ipython-input-12-4fa6b88aa415> in <module>() 
    16 # show the results 
    17 #output_notebook() 
---> 18 show(p) 

C:\Users\x\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\io.py in show(obj, browser, new) 
    300  if obj not in _state.document.roots: 
    301   _state.document.add_root(obj) 
--> 302  return _show_with_state(obj, _state, browser, new) 
    303 
    304 

C:\Users\x\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\io.py in _show_with_state(obj, state, browser, new) 
    310 
    311  if state.notebook: 
--> 312   comms_handle = _show_notebook_with_state(obj, state) 
    313   shown = True 
    314 

C:\Users\x\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\io.py in _show_notebook_with_state(obj, state) 
    334   comms_target = make_id() 
    335   publish_display_data({'text/html': notebook_div(obj, comms_target)}) 
--> 336   handle = _CommsHandle(get_comms(comms_target), state.document, state.document.to_json()) 
    337   state.last_comms_handle = handle 
    338   return handle 

C:\Users\x\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\document.py in to_json(self) 
    792   # this is a total hack to go via a string, needed because 
    793   # our BokehJSONEncoder goes straight to a string. 
--> 794   doc_json = self.to_json_string() 
    795   return loads(doc_json) 
    796 

C:\Users\x\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\document.py in to_json_string(self, indent) 
    785   } 
    786 
--> 787   return serialize_json(json, indent=indent) 
    788 
    789  def to_json(self): 

C:\Users\x\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\core\json_encoder.py in serialize_json(obj, encoder, indent, **kwargs) 
    97   indent = 2 
    98 
---> 99  return json.dumps(obj, cls=encoder, allow_nan=False, indent=indent, separators=separators, sort_keys=True, **kwargs) 

C:\Users\x\AppData\Local\Continuum\Anaconda3\lib\json\__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw) 
    235   check_circular=check_circular, allow_nan=allow_nan, indent=indent, 
    236   separators=separators, default=default, sort_keys=sort_keys, 
--> 237   **kw).encode(obj) 
    238 
    239 

C:\Users\x\AppData\Local\Continuum\Anaconda3\lib\json\encoder.py in encode(self, o) 
    197   # exceptions aren't as detailed. The list call should be roughly 
    198   # equivalent to the PySequence_Fast that ''.join() would do. 
--> 199   chunks = self.iterencode(o, _one_shot=True) 
    200   if not isinstance(chunks, (list, tuple)): 
    201    chunks = list(chunks) 

C:\Users\x\AppData\Local\Continuum\Anaconda3\lib\json\encoder.py in iterencode(self, o, _one_shot) 
    255     self.key_separator, self.item_separator, self.sort_keys, 
    256     self.skipkeys, _one_shot) 
--> 257   return _iterencode(o, 0) 
    258 
    259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, 

ValueError: Out of range float values are not JSON compliant 

答えて

3

私は同じエラーを持っていた私は、問題をデバッグ:私は私のプロットデータセット内のNaN値を持っていたとbokehserialize_json()機能(/core/json_encoder.pyに)はNaNの値を許可しません(理由はわかりません...)。この機能のreturn一部でallow_nan=False引数がjson.dumps()にあります:出力ファイルが生成されたとき((問題は、(それが上記serialize_json()関数を呼び出す)のみボケプロセスのio一部で発生

だからあなたが持っていますあなたのデータフレームでNaN値、例えば:

df = df.fillna('') 

ニースの日!:) this Pull Requestはバイナリ配列のシリアル化OPTIを追加するとき

2

NaNサポートがより良いサポートされますを交換しますonがマージされます。それは標準ではありませんので、これは— naninfは、IMO(悪質な監督公式JSONの仕様の一部ではありませんが、、パイソンJSONエンコーダでallow_nanを使用していない1月2017年ボケにボケ0.12.4で利用可能であるべきである私たちのコントロールの外)

0

をNAN値を除去した後、無限の価値があるかもしれない、それはinfなど、いくつかの無限の値は、それが動作するはずです、いくつかの方法をそれらの無限の値を削除している可能性がありますデータセット全体をトレース 。あなたは

df = df[~df.isin([np.nan, np.inf, -np.inf]).any(1)] 

参照して、それらの行を削除する任意のINF値を見つけた場合

df['column'].describe() 

はその後:solution here

0

まあそれはそれより私の経験のように働いて正確にあなたの質問への答えではありません1週間ボケ。私の場合、bokehからテキサスの例のようなプロットを作ろうとしています.....多くの不満の後、私はbokehやjsonなどがリストの最初の値(myList)に遭遇したときにNaNそれは、私は、それが他の位置にはNaNさんが含まれている場合でも正常に動作浮かぶように(はmyList [0])は、リストの最初の値を変更した場合、メッセージに

ValueError: Out of range float values are not JSON compliant

を与えてプロットすることを拒否します。これを考慮に入れて、これらのことがどのように機能するかを理解している人は、答えを提案します。私の場合、最初の値がナノでないようにデータを再構築することです。

関連する問題