Calculer la moyenne maximale de 4 mois de précipitations sur plusieurs années (Python)

Calculate Average Maximum 4 Months Rainfall Over Many Years



Calculer la moyenne maximale de 4 mois de précipitations sur plusieurs années (Python)

Écrivez le code manuscrit des travaux d'hydrologie à titre indicatif seulement
Type de données: fichier Excel, données pluviométriques sur 12 mois
image
Code de calcul: utilisez le module pandas pour lire le fichier excel et le trier

/* * Copyright Notice: No * file name : Rainfall_Calculate.py * creator : LiaoChaoming * Creation date: 2019/10/19 * File Description: 〈Calculate the multi-year average maximum rainfall of 4 months〉 */ #Import module import pandas as pd #Read excel file path = 'Excel file path' df = pd.read_excel(path) #Read the month value and calculate it, and output the total monthly precipitation array_1 = [] i = 0 while i <= 11: data=df.iloc[:,i].values #Read the value of the first row and second column, no nested list is needed here print('{1}Monthly precipitation data: {0}'.format(data,i)) sum_1 = sum(data) array_1.append(sum_1) i += 1 print('Total monthly precipitation:') print(array_1) #Calculate rainfall for up to four consecutive months array_2 = [] n = 0 while n <= 11: if n <= 8: sum_2 = sum(array_1[n:n+4]) else: k = 11-n sum_2 = sum(array_1[n:12])+sum(array_1[0:3-k]) n += 1 array_2.append(sum_2) print('Average rainfall for four consecutive months:') print(array_2) #Create dictionary print('The rainfall for the corresponding month (four months):') key_month = ('month1-4','month2-5','month3-6','month4-7','month5-8','month6-9','month7-10','month8-11','month9-12','month10-1','month11-2','month12-3') MyDict = dict(zip(key_month,array_2)) print(MyDict) #Sort MyDict_2 = sorted(MyDict.items(), key=lambda d:d[1],reverse = True) # dict.items() turns into a tuple, key= lambda d:d[0]#d[0] means a key, d[1] means a value. reverse# is False by default, sorted in ascending order. When the value is True, it is in descending order print('Average consecutive maximum four months of rainfall:') print(MyDict_2[0])

Résultat de sortie:
image