由于NaN,Boxplot子图未显示?

时间:2019-05-23 09:54:29

标签: python pandas matplotlib

在子图中绘制箱形图时遇到问题。我的数据是包含datetime index的{​​{1}}的时间序列。这是代码

NaNs

它显示了一个空图(下面的图(a))和fig, ax = plt.subplots(1,1, figsize=(5, 3)) ax.boxplot([df['col1'], df['col2']]) plt.show() 。删除'RuntimeWarning: Invalid value encountered in percentile interpolation=interpolation时,将显示该图,但我不想在进行框线绘图之前删除NaNs,因为结果不同。
enter image description here

使用以下代码时,它返回正确图(图(b)),但不返回子图

NaNs

我希望在子图中添加如图(b)所示的东西。

1 个答案:

答案 0 :(得分:0)

正如您正确地说的那样,问题可能出在列中。如果您不想删除NAN,请将其替换为0或您认为合适的值。

以下内容将起作用。

df.fillna(0, inplace=True)