【问题标题】:Calculate the min, max and mean windspeeds and standard deviations计算最小、最大和平均风速和标准偏差
【发布时间】:2019-12-11 20:26:20
【问题描述】:

计算前 52 个每周所有位置的最小、最大和平均风速以及风速的标准偏差
(假设第一周从 1961 年 1 月 2 日开始)周。

获取数据
https://github.com/prataplyf/Wind-DateTime/blob/master/wind_data.csv

不知道怎么解决

每个位置的每周平均值

          RTP    VAL   ....... . ..... ..  .. . . .. . . .. ... BEL   MAL
1961-1-1
1961-1-8
1961-1-15

【问题讨论】:

    标签: pandas


    【解决方案1】:

    加载数据:

    df = pd.read_csv('wind_data.csv')
    

    date转换为datetime并设置为索引

    df.date = pd.to_datetime(df.date)
    df.set_index('date', drop=True, inplace=True)
    

    为 1961 创建一个 DateFrame

    df_1961 = df[df.index < pd.to_datetime('1962-01-01')]
    

    为统计计算重新采样

    df_1961.resample('W').mean()
    df_1961.resample('W').min()
    df_1961.resample('W').max()
    df_1961.resample('W').std()
    

    绘制 1961 年的数据:

    fix, axes = plt.subplots(12, 1, figsize=(15, 60), sharex=True)
    for name, ax in zip(df_1961.columns, axes):
        ax.plot(df_1961[name], label='Daily')
        ax.plot(df_1961_mean[name], label='Weekly Mean Resample')
        ax.plot(df_1961_min[name], label='Weekly Min')
        ax.plot(df_1961_max[name], label='Weekly Max')
        ax.set_title(name)
        ax.legend()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-16
      • 2014-03-21
      • 1970-01-01
      • 2021-11-04
      • 2015-10-10
      相关资源
      最近更新 更多