python计算多站点n年每个月的降水平均值

#!usr/bin/env python
# -*- coding:utf-8 -*-
"""
@author: Su
@file: calculatejsjp.py
@time: 2023/06/09
@desc:
"""
import pandas as pd

# 读取数据
Data = pd.read_excel('processdata/rawdata/乌兰察布.xlsx')

#按站点分组并计算每月平均值
result = Data.groupby(['name','month'])['rain'].agg('mean')
print(result)

df = pd.DataFrame(result)

writer = pd.ExcelWriter('processdata/output.xlsx')
df.to_excel(writer,sheet_name='Sheet1')
writer._save()

得出的结果

 

posted @ 2023-06-27 17:07  秋刀鱼CCC  Views(199)  Comments(0Edit  收藏  举报