pandas 分组依据和日志添加

发布于 2025-01-17 07:48:48 字数 789 浏览 3 评论 0原文

我的第一个数据框是这样的:

在此处输入图像描述

我需要按日期进行分组并在“SEL”列上添加日志

所以,我可以像这样按日期进行分组:

df.groupby([df.index.date])["SEL"]

但公式是

> 10*math.log10(10**(df["SEL"]/10).sum())

有人可以帮助我吗?

我首先使用:

temp=0
for index,row in df.iterrows():
    temp+=10**(row["SEL"]/10)
sumadd=10*math.log10(temp)

这是唯一的方法吗?

这是几天的输出示例:

在此处输入图像描述

My first dataframe is this :

enter image description here

I need to make a group by date AND make a log add on column "SEL"

So, I can do the group by date like this :

df.groupby([df.index.date])["SEL"]

But the formula is

> 10*math.log10(10**(df["SEL"]/10).sum())

Anyone can help me please?

First i used :

temp=0
for index,row in df.iterrows():
    temp+=10**(row["SEL"]/10)
sumadd=10*math.log10(temp)

Is this the only way?

That's a example of output for several days :

enter image description here

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

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

发布评论

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

评论(1

看透却不说透 2025-01-24 07:48:48

groupby.transform 并将每个列的丢失值设置为每个日期,而无需上次

dates = df.index.normalize()
df['new'] = (10*np.log10((10**(df["SEL"]/10)).groupby(dates).transform('sum'))
                   .mask(dates.duplicated(keep='last')))

Create new column with GroupBy.transform and set missing values to all column per date without last by Series.mask:

dates = df.index.normalize()
df['new'] = (10*np.log10((10**(df["SEL"]/10)).groupby(dates).transform('sum'))
                   .mask(dates.duplicated(keep='last')))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文