gpt4 book ai didi

python - 如何按列求和

转载 作者:行者123 更新时间:2023-11-28 21:27:10 24 4
gpt4 key购买 nike

我有一个数据文件,我想在其中按列求和。

数据看起来像:

Date;Heure;U12_min;U12_max;U12_moy
13/07/12-15:10:02;581072;41719;42058;41892
13/07/12-15:20:01;581088;41610;42108;41897
13/07/12-15:30:01;581105;41810;42048;41931
13/07/12-15:40:01;581122;41483;41988;41798
...
14/07/12-00:00:01;581955;42013;42377;42210
14/07/12-00:10:01;581972;41502;42117;41851
14/07/12-00:20:01;581988;41477;42349;42135
14/07/12-00:30:00;582005;42092;42517;42264
14/07/12-00:40:00;582022;41766;42653;42032
14/07/12-00:50:01;582038;41836;42267;42069
14/07/12-01:00:01;582055;42056;42334;42214

这是我的代码:

from pandas import *

fich = 'D://ENERGIE//test2.csv'
df = read_csv(fich, delimiter=";", index_col="Date")
df.sum["Heure"]
print df

我收到以下消息

df.sum["Heure"]
TypeError: 'instancemethod' object is not subscriptable

最佳答案

pandas 的 groupby 函数不应该与 sum 一起使用吗?

from pandas import *

fich = 'D://ENERGIE//test2.csv'
df = read_csv(fich, delimiter=";", index_col="Date")
sumValue = df.groupby("Heure").sum()
print sumValue

关于python - 如何按列求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11538574/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com