How can I calculate maximum precipitation data for each year from 30 years daily precipitation data which is in excel file using python?

Viewed 11

I have more than 30 years daily precipitation data in excel. In excel columns are "Month", "Day", "Year", "PRCP", "TMAX and "TMIN". I try to use below code to get max precipitation, but struggle to run through each year to get max precipitation for each year with date. As i have daily data, so in year column i have same year for 365 times, so from my code i can't iterate to get daily maximum data so can anyone help me to make code to get that result.

from fileinput import filename
import ntpath
import glob
from operator import index
from tkinter.messagebox import YES
import pandas as pd
import numpy as np
import datetime
import re
from openpyxl.workbook import Workbook


# Define file location in a computer
file_path = "C:/Users/binit/Five_stations/*.xlsx"

#Define Output location
output_path = "C:/Users/binit/Five_stations/Output.xlsx"

# To read each excel file to calculate maximum precipitation of a year with their month and day
directory = file_path
for filename in glob.glob(file_path):
    print(filename)
    df = pd.read_excel(filename)
    data = pd.DataFrame(df, columns=["Month", "Day", "Year", "PRCP","TMAX","TMIN"])
    print(data)
    df_grouped = df.groupby("Year")
    for x in df_grouped:
        print(df["PRCP"].max()
0 Answers
Related