Spaces:
Runtime error
Runtime error
Zack
commited on
Commit
·
05bf296
1
Parent(s):
4155129
fix: Add date.floor method to fix issues with invalid hr 24:00:00 data
Browse files
app.py
CHANGED
|
@@ -81,30 +81,31 @@ def clean_data(df):
|
|
| 81 |
else:
|
| 82 |
raise ValueError("Dataframe does not contain necessary columns.")
|
| 83 |
|
| 84 |
-
def
|
| 85 |
-
#
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
| 108 |
|
| 109 |
outputs = gr.outputs.Image()
|
| 110 |
|
|
|
|
| 81 |
else:
|
| 82 |
raise ValueError("Dataframe does not contain necessary columns.")
|
| 83 |
|
| 84 |
+
def clean_data(df):
|
| 85 |
+
# Check if the DataFrame already contains the correct columns
|
| 86 |
+
if "timestamp" in df.columns and "value" in df.columns:
|
| 87 |
+
df["timestamp"] = pd.to_datetime(df["timestamp"])
|
| 88 |
+
return df
|
| 89 |
+
|
| 90 |
+
# Check if DataFrame contains the columns to be converted
|
| 91 |
+
elif "Date" in df.columns and "Hour" in df.columns and "Hourly_Labor_Hours_Total" in df.columns:
|
| 92 |
+
# Convert "Date" and "Hour" columns into datetime format
|
| 93 |
+
df["timestamp"] = pd.to_datetime(df["Date"]) + pd.to_timedelta(df["Hour"].astype(int), unit='h')
|
| 94 |
+
|
| 95 |
+
# Handle the case where hour is 24
|
| 96 |
+
df.loc[df["timestamp"].dt.hour == 24, "timestamp"] = df["timestamp"] + pd.DateOffset(days=1)
|
| 97 |
+
df["timestamp"] = df["timestamp"].dt.floor('h')
|
| 98 |
+
|
| 99 |
+
# Keep only necessary columns
|
| 100 |
+
df = df[["timestamp", "Hourly_Labor_Hours_Total"]]
|
| 101 |
+
|
| 102 |
+
# Rename column
|
| 103 |
+
df.rename(columns={"Hourly_Labor_Hours_Total": "value"}, inplace=True)
|
| 104 |
+
|
| 105 |
+
return df
|
| 106 |
+
|
| 107 |
+
else:
|
| 108 |
+
raise ValueError("Dataframe does not contain necessary columns.")
|
| 109 |
|
| 110 |
outputs = gr.outputs.Image()
|
| 111 |
|