I agree with @pturmel, it doesn’t seem from your code that you are really interested in historical data.
If you really do want historical data then why are you removing any date time information that would make the data meaningful?
In addition to that I am curious about what makes the last row special?
connected = [index[i] for i in range(1, num_cols, 3) if py[num_rows-1][i]==1]
inducted = [index[i] for i in range(2, num_cols, 3) if py[num_rows-1][i]==1]
safe = [index[i]-1 for i in range(3, num_cols, 3) if py[num_rows-1][i]==1]
Assuming that each row is an individual bot if that last bot is not inducted, then your code will fall apart (IMHO) because the inducted list which you use later to build your data will be empty and your function will at best return an empty dataset, but in all likely hood will error stating that the number of columns in data doesn’t match the number of column headers.
All of that being said, if you really do, for whatever reason, want historical data with the date column removed then your code for that can be simplified
# Query tag history
dsHistory = system.tag.queryTagHistory(paths=paths, endDate=endTime, intervalHours=-24)
# Create the aggregated table
headers = ["Alphabot", "Connected", "Inducted", "Safety_OK"]
data = [[dsHistory.getValueAt(row,col) for col in range(1,dsHistory.getColumnCount())] for row in range(dsHistory.getRowCount())]
Or if you really insist on using a pyDataSet then
# Query tag history
dsHistory = system.tag.queryTagHistory(paths=paths, endDate=endTime, intervalHours=-24)
dsHistory = system.dataset.toPyDataSet(dsHistory)
# Create the aggregated table
headers = ["Alphabot", "Connected", "Inducted", "Safety_OK"]
data = [[value for i, value in enumerate(row) if i > 0] for row in dsHistory]