计数,条形,每个熊猫数据框直方图子图

发布于 2025-01-25 10:42:23 字数 787 浏览 6 评论 0原文

我每小时要进行单独的旅行距离直方图。但是,为了进一步计算,我想为所有直方图中的每个直方图中的每个垃圾箱的值。

到目前为止,我有以下内容:

    df['Distance'].hist(by=df['Departuretime'], color = 'red', 
            edgecolor = 'black',figsize=(15,15),sharex=True,density=True)

在我的情况下,这是一个具有21个小直方图的数字。

在单个直方图的情况下,我会粘贴计数,垃圾箱,bars =在整个行的前面,变量counts将包含我正在寻找的数据,但是,这种情况不起作用。

理想情况下,我想要每个直方图的数据框架或某种形式的列表,其中包含箱的密度值。我希望有人可以帮助我!提前致谢!

编辑:

我正在使用的数据,大约2500列,距离为float64,dewdurationeption s str str

我收到的直方图

我想知道y轴的所有这些直方图中的直方图 每个条的值,最好是在距离式包装的数据框架中,作为行,小时为列

I am making separate histograms of travel distance per departure hour. However, for making further calculations I'd like to have the value of each bin in a histogram, for all histograms.

Up until now, I have the following:

    df['Distance'].hist(by=df['Departuretime'], color = 'red', 
            edgecolor = 'black',figsize=(15,15),sharex=True,density=True)

This creates in my case a figure with 21 small histograms.

With single histograms, I'd paste counts, bins, bars = in front of the entire line and the variable counts would contain the data I was looking for, however, in this case it does not work.

Ideally I'd like a dataframe or list of some sort for each histogram, containing the density values of the bins. I hope someone can help me out! Thanks in advance!

Edit:

Data I'm using, about 2500 columns of this, Distance is float64, the Departuretime is str

Histogram output I'm receiving

Of all these histograms I want to know the y-axis value of each bar, preferably in a dataframe with the distance binning as rows and the hours as columns

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稚气少女 2025-02-01 10:42:23

通过使用“剪切”函数,您可以直接从数据框架而不是从图形中提取所请求的数据。这对误差敏感性较小。

df['DistanceBin'] = pd.cut(df['Distance'], bins=10)

然后,您可以使用pivot_table来获取一个表格,并分别按照您的要求,分别将decortbin和dectionbin时的计数作为行和列。

df.pivot_table(index='DistanceBin', columns='Departuretime', aggfunc='count')

By using the 'cut' function you can withdraw the requested data directly from your dataframe, instead of from the graph. This is less error-sensitive.

df['DistanceBin'] = pd.cut(df['Distance'], bins=10)

Then, you can use pivot_table to obtain a table with the counts for each combination of DistanceBin and Departuretime as rows and columns respectively as you asked.

df.pivot_table(index='DistanceBin', columns='Departuretime', aggfunc='count')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文