Spaces:
Runtime error
Runtime error
File size: 1,986 Bytes
d0e04e1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | import pandas as pd
import datetime
def get_time(data, time=datetime.datetime.now()):
current_date = time.strftime("%Y-%m-%d %H")
return data[data['date'] == current_date]
def get_data(data):
df = pd.read_csv(data, parse_dates=[0])
df.rename(columns={df.columns[0]: 'date'}, inplace=True)
df['date'] = df['date'].dt.strftime("%Y-%m-%d %H")
df = get_time(df)
timeseries = df.date.values
temp = df.predicted_mean.values
return timeseries, temp
def get_data_all(data):
df = pd.read_csv(data, parse_dates=[0])
df.rename(columns={df.columns[0]: 'date'}, inplace=True)
df['years'] = df['date'].dt.strftime("%Y")
df['months'] = df['date'].dt.strftime("%m")
df['days'] = df['date'].dt.strftime("%A")
df['daysn'] = df['date'].dt.strftime("%d")
df['hours'] = df['date'].dt.strftime("%H").astype(int)
df['temp'] = df.predicted_mean.values.astype(int)
df = df[df['hours'] % 3 == 0]
return df.drop(columns=['predicted_mean'])
def to_dict(df):
data_dict = {}
# Loop through years
for year in df['years'].unique():
data_dict[year] = {}
# Filter data for the current year
year_data = df[df['years'] == year]
# Loop through months
for month in year_data['months'].unique():
data_dict[year][month] = {}
# Filter data for the current month
month_data = year_data[year_data['months'] == month]
# Loop through unique dates
for date in month_data['daysn'].unique():
data_dict[year][month][date] = {}
# Filter data for the current date
date_data = month_data[month_data['daysn'] == date]
# Get the name of the day
day_name = date_data['days'].values[0]
data_dict[year][month][date]['day_name'] = day_name
# Loop through the hours and store the corresponding temperature
for hour in date_data['hours'].unique():
temp = date_data[date_data['hours'] == hour]['temp'].values[0]
data_dict[year][month][date][hour] = temp
return data_dict |