ARTICLE AD BOX
I'm working on a dashboard to interactively display ride wait times in a theme park. I've got a script running that polls a web API for wait times every 5 minutes. From that script, I have a series of csv files, sorted by date and ride, each containing the time the sample was taken, and the wait time for each ride.
In my dash application, I use pandas to read the csv into a data frame, and then graph that using plotly. It works fine with one ride, but when multiple rides are present, some entries show out of order:
Note the red line going off to be crazy.
These are the functions I use to load the data:
def update_data_frame(self, name, date): name = name.replace(' ', '_') df = self.load_data(date, name, "tds") self.frame = pd.concat([self.frame, df], axis=0, ignore_index=True) self.frame = self.frame.sort_values(by="last_updated", ignore_index=True) self.fig = px.line( self.frame, x='last_updated', y='wait_time', title="Wait Times", labels={'last_updated': "Last Updated", 'wait_time': "Wait Time (min)"}, color='ride' ) def load_data(self, date, ride_name, park_name): filename = f"{os.getenv('SAVE_PATH')}{park_name}/{date}/{date}_{ride_name}.csv" df = pd.read_csv(filename, header=0, delimiter = ', ') for key, entry in df["last_updated"].items(): entry = re.match(r".* (\d\d:\d\d):\d\d\+09:00", entry)[1] print(f"{ride_name} {entry}") df.loc[key, "last_updated"] = entry df["ride"] = full(len(df), f"{date}-{ride_name}") return dfBy inspecting the data, I've noticed that the weird jumps only happen when a sample is not taken at the same time every day. I tried to resolve that by truncating to minutes, but sometimes the API I used updated off-schedule, and then you get the craziness I'm trying to fix.
I tried printing the dataframe after adding these rides to it to see if the data is out of order in there, but it seems okay to me:
last_updated wait_time is_open ride 0 00:01 0 False 2026-03-18-Aquatopia 1 00:01 0 False 2026-02-01-20,000_Leagues_Under_the_Sea 2 00:06 0 False 2026-02-01-20,000_Leagues_Under_the_Sea 3 00:06 0 False 2026-03-18-Aquatopia 4 00:11 0 False 2026-03-18-Aquatopia .. ... ... ... ... 569 23:46 0 False 2026-03-18-Aquatopia 570 23:51 0 False 2026-02-01-20,000_Leagues_Under_the_Sea 571 23:51 0 False 2026-03-18-Aquatopia 572 23:56 0 False 2026-03-18-Aquatopia 573 23:56 0 False 2026-02-01-20,000_Leagues_Under_the_SeaIf the data was out of order in the dataframe, I would expect to see the extra entries at the end, as they are at the end of the graph.
Any help with this would be greatly appreciated.
