-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate range
14 lines (14 loc) · 952 Bytes
/
date range
1
2
3
4
5
6
7
8
9
10
11
12
13
14
def calculate_date_range(input_file, output_file):
# Read the Excel file with multiple sheets into a dictionary of DataFrames
dfs = pd.read_excel(input_file, sheet_name=None)
# Create a new DataFrame to store the observation date ranges
result_df = pd.DataFrame(columns=['Sheet', 'Min_Observation_Date', 'Max_Observation_Date'])
# Iterate through each sheet and calculate the date range
for sheet_name, df in dfs.items():
if 'observation_date' in df.columns:
min_date = df['observation_date'].min()
max_date = df['observation_date'].max()
result_df = result_df.append({'Sheet': sheet_name, 'Min_Observation_Date': min_date, 'Max_Observation_Date': max_date}, ignore_index=True)
# Write the result DataFrame to a new Excel file
with pd.ExcelWriter(output_file, engine='xlsxwriter') as writer:
result_df.to_excel(writer, sheet_name='ObservationDateRanges', index=False)