Basically, what I’m trying to do is detect the days inside a .CSV file, and once these days have been extracted, display hour by hour OR from a specific hour to another hour.
What i did for extracting Date Days was:
import pandas
from tkinter import filedialog as ASK
from tkinter import messagebox
import datetime as dt
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
class Presion:
def __init__(self):
self.Doc1 = None
self.Doc2 = None
self.excel1 = None
self.excel2 = None
self.DiasDisponibles1 = None
self.DiasDisponibles2 = None
self.DayList1 = []
self.DayList2 = []
self.Plot1X = []
self.Plot1Y = []
self.Plot2X = []
self.Plot2Y = []
self.DayEndsValue1 = []
self.DayEndsValue2 = []
pass
def ReadPresion1(self):
self.Doc1 = ASK.askopenfilename(initialdir=" /", title="SELECT .CSV FILE!!", filetypes=(("files", "*.csv"), ("all files", "*.*")))
try:
self.excel1 = pandas.read_csv(self.Doc1, sep="t", encoding="utf-16")
except FileNotFoundError:
messagebox.showerror(title="INVALID!", message="Make sure select .CSV FILES!")
else:
self.excel1.fillna(0, inplace=True)
self.excel1.columns = ["Hour", "Date", "Value"]
Last_Date = None
DayEnds = 0
for Date in self.excel1.loc[:,"Date"]:
DayEnds += 1
if Date != Last_Date:
self.DayList1.append(Date)
self.DayEndsValue1.append(DayEnds)
Last_Date = Date
self.DayEndsValue1.append(DayEnds)
print(self.DayList1)
print(self.DayEndsValue1)
for Hour in range(self.DayEndsValue1[0], self.DayEndsValue1[1]):
ValueX = self.excel1.loc[Hour, "Hour"]
self.Plot1X.append(ValueX)
for Value in range(self.DayEndsValue1[0], self.DayEndsValue1[1]):
ValueY = self.excel1.loc[Value, "Value"]
self.Plot1Y.append(ValueY)
# Figura1Presion = Figure(figsize=(7,6), dpi=100)
# Figura1Presion.add_subplot(111).plot(self.Plot1X, self.Plot1Y)
Figura1ASDF = plt.figure(figsize=(12,7))
Figura1ASDF.add_subplot(111).plot(self.Plot1X, self.Plot1Y)
locator = mdates.AutoDateLocator(minticks=12, maxticks=24)
plt.gcf().axes[0].xaxis.set_major_locator(locator)
plt.xticks(rotation=45)
plt.gcf().autofmt_xdate()
return Figura1ASDF
def getDaysP1(self):
return self.DayList1
and then in my main script i have a set up tkinter program running where i set up some button to ask .CSV file, etc
Here some functionallity:
def showPlotPresion1():
Figure1 = OBJ_PRESION.ReadPresion1()
DaysP1 = OBJ_PRESION.getDaysP1()
showDaysPresion1(DaysP1)
canvas = FigureCanvasTkAgg(Figure1, master=WindowPresion) # A tk.DrawingArea.
canvas.draw()
canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
toolbar = NavigationToolbar2Tk(canvas, WindowPresion)
toolbar.update()
canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
def showDaysPresion1(ListPresion1):
optionsSelect = StringVar()
optionsSelect.set("04/26/2021")
TextP1 = Label(WindowPresion, text="Dias Disponibles Presion 1 -->")
TextP1.pack(anchor="w", side=LEFT)
List1 = OptionMenu(WindowPresion, optionsSelect, *ListPresion1)
List1.pack(anchor="w", side=LEFT)
How do I extract available hours from these read-through days?
Here is the VSC format:
CSV FILE