seaborn: Selected KDE bandwidth is 0. Cannot estimate density

后端 未结 5 767
北恋
北恋 2021-01-04 18:32
import pandas as pd
import seaborn as sns

ser_test = pd.Series([1,0,1,4,6,0,6,5,1,3,2,5,1])
sns.kdeplot(ser_test, cumulative=True)

The above code g

5条回答
  •  爱一瞬间的悲伤
    2021-01-04 18:53

    if you don't want to wait for the seaborn git update to get released in a stable version, you can try one of the solutions in the issue page. specifically henrymartin1's suggestion to try manually passing in a small bandwidth inside a try/catch block (suggested by ahartikainen) which grabs the text of this specific error (so other errors still get raised):

    try:
        sns.distplot(df)
    except RuntimeError as re:
        if str(re).startswith("Selected KDE bandwidth is 0. Cannot estimate density."):
            sns.distplot(df, kde_kws={'bw': 0.1})
        else:
            raise re
    

    This worked for me.

提交回复
热议问题