UsageDate CustID1 CustID2 .... CustIDn
0 2018-01-01 00:00:00 1.095
1 2018-01-01 01:00:00 1.129
2 2018-01-01 02:00:00 1.165
3 2018-01-01 04:00:00 1.697
.
.
m 2018-31-01 23:00:00 1.835 (m,n)
数据帧(df)有m行和n列。m是一个小时时间序列指数,从每月的第一个小时开始到每月的最后一个小时。 栏目是近10万的客户。 数据帧的每个单元的值都是能量消耗值
对于每个客户,我需要计算: 1) 平均每小时使用量-所以基本上是一个月内每天第一小时的平均值,一个月内每天第二小时的平均值等等
2)各客户使用量汇总
3)前3个使用小时-对于客户x,可以是“2018-01-01 01:00:00”, “2018-11-01 05:00:00”“2018-21-01 17:00:00”
4)倒数第3个使用小时-与上述解释类似
5)每个客户当月的平均使用量
我的主要问题是如何将每个客户的数据和一天中的某个小时或一天中的某个时间进行聚合
为了总结每个客户的使用情况,我尝试了:
df_temp = pd.DataFrame(columns=["TotalUsage"])
for col in df.columns:
`df_temp[col,"TotalUsage"] = df[col].apply.sum()`
然而,这个和我尝试过的许多版本并没有帮助我解决这个问题
请帮助我找到解决这些问题的方法和方法
另外,由于数据帧很大,如果我们可以讨论计算复杂性以及如何减少计算时间,这将是很有帮助的
这看起来像是pandas.groupby的工作
(我没有测试代码,因为我没有一个好的样本数据集来工作。如果有错误,请告诉我。)
对于某些要求,您需要添加一个包含小时的列:
1)按小时平均
2)按用户求和
3)客户最高使用量。倒数第三个使用小时-与上面的解释类似。我不太明白你想要的结果,你可能在这个问题上问了太多不同的问题。如果您想要的是小时而不是值,我认为您可能需要遍历列。添加一个示例可能会有所帮助
4)相同意见
5)指顾客
我不确定这是否是您要查找的所有信息,但它将为您指明正确的方向:
输出:
对于top和bottom 3,如果要查找跨行的最小和,则:
相关问题 更多 >
编程相关推荐