大Pandas直方图的处理

2024-04-26 23:25:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我在pandas中有一个很大的数据帧。在绘制直方图时,我想用较低的频率删除特定范围的值(不是单个值)。你知道吗

对于下面的图像,假设我想删除Dataframe变量的所有值,这些值对应于低于20的count/frequency。有人有什么解决办法吗?你知道吗

# PR has value between 0 to 1700 
data['PR'].hist(bins = 160) #image on the left
data_openforest['PR'].hist(bins = 160) #image on the right

enter image description hereenter image description here


Tags: the数据图像imagedataframepandasdataon
1条回答
网友
1楼 · 发布于 2024-04-26 23:25:28

使用pd.切割这样应该行得通:

out = pd.cut(data_openforest['PR'], bins=160)
counts = out.value_counts(sort=False)
counts[counts > 20].plot.bar()
plt.show()

如果要过滤数据帧,必须执行以下操作:

data_openforest['bin'] = pd.cut(data_openforest['PR'], bins=160)
bin_freq = data_openforest.groupby('bin').count()
data_openforest = data_openforest.merge(bin_freq, 
                                        on='bin', 
                                        how='left',
                                        suffixes=("_bin", 
                                                  "_bin_freq"))

然后你可以很容易地过滤你的数据帧。然后你必须做一个条形图,而不是历史图。你知道吗

相关问题 更多 >