Code With Dates HARDCODED
Code With Dates HARDCODED
import random
import math
import numpy as np
import xml.etree.ElementTree as ET
result_list = []
tree = ET.parse('DM SHORT.xml')
root = tree.getroot()
missing_data = root.find('MissingData')
for sheet in root.findall('Sheet'):
sheet_name = sheet.find('Name').text
print('Sheet:', sheet_name)
# Read the excel file
df = pd.read_excel('/content/dummy.xlsx', sheet_name=sheet_name, header=2)
columns = sheet.find('Columns')
include_columns = columns.find('IncludeColumns')
for column in include_columns.findall('Column'):
col_name = column.find('Name').text
print(col_name)
missing_data = column.find('MissingData')
if missing_data is not None:
limit = missing_data.find('Limit')
if limit is not None:
print("Missing Data Limit for Column:", limit.text)
last_known_value = missing_data.find('LastKnownValue')
if last_known_value is not None:
print("Last Known Value for Column:", last_known_value.text)
result[col_name] = None
for i in result.index:
try:
target_date = result.at[i, 'DateTime'].strftime('%d.%m.%Y')
target_hour = result.at[i, 'DateTime'].strftime('%H:00')
result.set_index('DateTime', inplace=True)
result.index = result.index.strftime('%d.%m.%Y %H:%M:%S')
result_list.append((sheet_name, result))
print(result_list)
# Write the results to an Excel file
with pd.ExcelWriter('RES1.xlsx') as writer:
for sheet_name, result in result_list:
result.to_excel(writer, sheet_name=sheet_name)