使用直方图绘制Pandas数据帧时,样本数据如下:
我遇到了这个错误。
奇怪的是,我使用的解决方法如下,在不使用ROUND的情况下。
distance
0 5.680195
2 0.000000
3 7.974658
4 2.461387
5 9.703089
我用来绘图的代码
import matplotlib.pyplot as plt
plt.hist(df['distance'].values)
plt.show()
我遇到了这个错误。
"ValueError: range parameter must be finite."
my attempt
df['Round_Distance'] = df['distance'].round(1)
0 5.7
2 0.0
3 8.0
4 2.5
5 9.7
重新绘制图表,出现新的错误。
plt.hist(df['Round_Distance'].values)
plt.show()
ValueError: max must be larger than min in range parameter.
奇怪的是,我使用的解决方法如下,在不使用ROUND的情况下。
df['distance'].hist(bins=[0,25,50,75,100,125,150,175], color='g')
df[np.isfinite(df['distance'])]
需要多长时间?它应该非常快... - sacuLdf = pd.DataFrame({'distance':np.random.choice(np.concatenate([np.linspace(0,10,1000), np.array([np.nan]), np.array([np.inf])]), 1000000)})
- sacuL