This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df = pd.read_csv('C:/Users/..../data.csv') | |
for i in range(0,len(df)): | |
while len(str(df.iloc[i][1]).replace('.0','')) < 4: | |
df.iloc[i,1] = '0' + str(df.iloc[i][1]).replace('.0','') | |
temp = datetime.datetime.strptime(str(df.iloc[i][0]).replace('.0','') + str(df.iloc[i][1]).replace('.0',''),'%Y%m%d%H%M') | |
df.iloc[i,0] = temp.strftime('%B') | |
df.iloc[i,1] = temp.strftime('%I%p') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df = df.groupby(['Month','Hour'],sort=False,as_index=False).mean().round(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
month_hours = {'January': {'12AM': None, '01AM': None, '02AM': None, '03AM': None, '04AM': None, '05AM': None, | |
'06AM': None, '07AM': None, '08AM': None, '09AM': None, '10AM': None, '11AM': None, | |
'12PM': None, '01PM': None, '02PM': None, '03PM': None, '04PM': None, '05PM': None, | |
'06PM': None, '07PM': None, '08PM': None, '09PM': None, '10PM': None, '11PM': None}, | |
.... | |
'December': {'12AM': None, '01AM': None, '02AM': None, '03AM': None, '04AM': None, '05AM': None, | |
'06AM': None, '07AM': None, '08AM': None, '09AM': None, '10AM': None, '11AM': None, | |
'12PM': None, '01PM': None, '02PM': None, '03PM': None, '04PM': None, '05PM': None, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(len(df)): | |
month_hours[df.iloc[i][0]][df.iloc[i][1]] = df.loc[i]['Value'] | |
data_rows = list(month_hours.values()) | |
data = [] | |
for i in range(0,len(data_rows)): | |
data.append(list(data_rows[i].values())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig = px.imshow(data, | |
labels=dict(x="Hour", y="Month", color="Value"), | |
x=['12AM','01AM','02AM','03AM','04AM','05AM', | |
'06AM','07AM','08AM','09AM','10AM','11AM', | |
'12PM','01PM','02PM','03PM','04PM','05PM', | |
'06PM','07PM','08PM','09PM','10PM','11PM'], | |
y=['January','February','March','April','May','June', | |
'July','August','September','October','November','December'] | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
st.title('Month vs. Hour Heatmap') | |
st.title('Dataframe') | |
st.dataframe(df) | |
st.markdown(download_csv('Heatmap Dataframe',pd.DataFrame(df)),unsafe_allow_html=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def download_csv(name,df): | |
csv = df.to_csv() | |
base = base64.b64encode(csv.encode()).decode() | |
file = (f'<a href="data:file/csv;base64,{base}" download="%s.csv">Download file</a>' % (name)) | |
return file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import create_engine | |
import psycopg2 | |
import pandas as pd | |
import streamlit as st |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
engine = create_engine("postgresql://<username>:<password>@localhost:5432/records_db") | |
engine_dataset = create_engine("postgresql://<username>:<password>@localhost:5432/datasets_db") | |
engine.execute("CREATE TABLE IF NOT EXISTS records (name text PRIMARY KEY, details text[])") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def write_record(name,details,engine): | |
engine.execute("INSERT INTO records (name,details) VALUES ('%s','%s')" % (name,details)) | |
def read_record(field,name,engine): | |
result = engine.execute("SELECT %s FROM records WHERE name = '%s'" % (field,name)) | |
return result.first()[0] | |
def update_record(field,name,new_value,engine): | |
engine.execute("UPDATE records SET %s = '%s' WHERE name = '%s'" % (field,new_value,name)) |