我有以下数据帧对象df
。它是一个列有发车日期、预定发车时间和列车公司的列车时刻表。你知道吗
import pandas as pd
df =
Year Month DayofMonth DayOfWeek DepartureTime Train Origin
Datetime
1988-01-01 1988 1 1 5 1457 BritishRail Leeds
1988-01-02 1988 1 2 6 1458 DeutscheBahn Berlin
1988-01-03 1988 1 3 7 1459 SNCF Lyons
1988-01-02 1988 1 2 6 1501 BritishRail Ipswich
现在,我想对这个时间序列重新取样,列出某个铁路公司每周从这个车站出发的次数。你知道吗
例如,每周有多少英国火车离开这个车站?每周有多少英国火车从利兹出发离开这个车站?你知道吗
我怀疑结果是熊猫系列的对象。你知道吗
我每周都试着买英国铁路
BR_weekly = df[df['Train']=='BritishRail'].resample("W", how='sum')
但这并没有给我一个时间序列的形式
Datetime Number of trains
i.e.
Datetime
1988-01-03 434
1988-01-10 982
1988-01-17 989
Freq: W-SUN, dtype: int64
我怎样才能解决这个问题?你知道吗
我的输入数据(添加和更改某些日期):
您可以使用^{} by ^{} 和列
Train
的计数值。你知道吗或者您可以通过} :
count
选择列Train
和^{编辑:
我认为您不能使用
sum
,因为它在Train
列中串联字符串:选择一列} 的
Train
,其中是使用^{BritishRail
,并用count
而不是sum
对其重新采样:相关问题 更多 >
编程相关推荐