Spaces:
Runtime error
Runtime error
Zack
commited on
Commit
·
e62a721
1
Parent(s):
03592e6
fix: Add check for existing correct columns
Browse files
app.py
CHANGED
|
@@ -60,22 +60,26 @@ def plot_anomalies(df_test_value, data, anomalies):
|
|
| 60 |
return fig
|
| 61 |
|
| 62 |
def clean_data(df):
|
| 63 |
-
# Check if
|
| 64 |
-
if "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
# Convert "Date" and "Hour" columns into datetime format
|
| 66 |
df["timestamp"] = pd.to_datetime(df["Date"] + ' ' + df["Hour"].astype(str) + ":00:00")
|
|
|
|
| 67 |
# Keep only necessary columns
|
| 68 |
df = df[["timestamp", "Hourly_Labor_Hours_Total"]]
|
|
|
|
| 69 |
# Rename column
|
| 70 |
df.rename(columns={"Hourly_Labor_Hours_Total": "value"}, inplace=True)
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
df.rename(columns={"Hourly_Labor_Hours_Total": "value"}, inplace=True)
|
| 75 |
-
df = df[["timestamp", "value"]]
|
| 76 |
else:
|
| 77 |
-
raise ValueError("
|
| 78 |
-
return df
|
| 79 |
|
| 80 |
def master(file):
|
| 81 |
# read file
|
|
|
|
| 60 |
return fig
|
| 61 |
|
| 62 |
def clean_data(df):
|
| 63 |
+
# Check if the DataFrame already contains the correct columns
|
| 64 |
+
if "timestamp" in df.columns and "value" in df.columns:
|
| 65 |
+
df["timestamp"] = pd.to_datetime(df["timestamp"])
|
| 66 |
+
return df
|
| 67 |
+
|
| 68 |
+
# Check if DataFrame contains the columns to be converted
|
| 69 |
+
elif "Date" in df.columns and "Hour" in df.columns and "Hourly_Labor_Hours_Total" in df.columns:
|
| 70 |
# Convert "Date" and "Hour" columns into datetime format
|
| 71 |
df["timestamp"] = pd.to_datetime(df["Date"] + ' ' + df["Hour"].astype(str) + ":00:00")
|
| 72 |
+
|
| 73 |
# Keep only necessary columns
|
| 74 |
df = df[["timestamp", "Hourly_Labor_Hours_Total"]]
|
| 75 |
+
|
| 76 |
# Rename column
|
| 77 |
df.rename(columns={"Hourly_Labor_Hours_Total": "value"}, inplace=True)
|
| 78 |
+
|
| 79 |
+
return df
|
| 80 |
+
|
|
|
|
|
|
|
| 81 |
else:
|
| 82 |
+
raise ValueError("Dataframe does not contain necessary columns.")
|
|
|
|
| 83 |
|
| 84 |
def master(file):
|
| 85 |
# read file
|