从 15 分钟的时间序列数据计算一年中的哪一天

乘风 python 223

原文标题calculate day of the year from 15minute timeseries data

我想要一年中的某一天的专栏。如何使用重新采样到每日条目的 15 分钟间隔数据计算一年中的哪一天。以下代码为每 15 分钟间隔生成一年中的某一天,但我只想要每一天的一年中的某一天。

我也尝试重新采样“时间”,但这不起作用。有人对我如何获得一年中的一天有任何建议吗?

df = pd.read_csv("D:/time-series.csv")

df = df.set_index(pd.DatetimeIndex(df["Time"]))
day_of_year = pd.DatetimeIndex(df["Time"]).dayofyear
#time = df["Time"].resample("24H")
pp = df["precip"].resample("24H").sum()

当前结果

day_of_year
Int64Index([182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
            ...
            366, 366, 366, 366, 366, 366, 366, 366, 366, 366],
           dtype='int64', name='Time', length=30720)

预期结果

day_of_year
[182,183,184,...,366]

原文链接:https://stackoverflow.com//questions/71962274/calculate-day-of-the-year-from-15minute-timeseries-data

回复

我来回复
  • Code Different的头像
    Code Different 评论

    因为我没有你的数据文件,所以盲打:

    df = pd.read_csv("D:/time-series.csv", parse_dates=["Time"], index_col="Time")
    pp = df["precip"].resample("24H").sum()
    day_of_year = pp.index.dayofyear
    
    2年前 0条评论