Zack commited on
Commit
287c811
·
1 Parent(s): 2c107c1

fix: Cleaning data

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -80,9 +80,13 @@ def clean_data(df):
80
  # Rename column
81
  df.rename(columns={"Hourly_Labor_Hours_Total": "value"}, inplace=True)
82
 
83
- elif "Date_CY" in df.columns and "Store" in df.columns and "Net_Sales_CY" in df.columns:
84
- # Convert "Date_CY" and "Store" columns into datetime format
85
- df["timestamp"] = pd.to_datetime(df["Date_CY"] + " " + df["Store"].astype(str) + ":00:00")
 
 
 
 
86
 
87
  # Keep only necessary columns
88
  df = df[["timestamp", "Net_Sales_CY"]]
 
80
  # Rename column
81
  df.rename(columns={"Hourly_Labor_Hours_Total": "value"}, inplace=True)
82
 
83
+ elif "Date_CY" in df.columns and "Hour" in df.columns and "Net_Sales_CY" in df.columns:
84
+ # Convert "Date_CY" and "Hour" columns into datetime format
85
+ df["timestamp"] = pd.to_datetime(df["Date_CY"]) + pd.to_timedelta(df["Hour"].astype(int), unit='h')
86
+
87
+ # Handle the case where hour is 24
88
+ df.loc[df["timestamp"].dt.hour == 24, "timestamp"] = df["timestamp"] + pd.DateOffset(days=1)
89
+ df["timestamp"] = df["timestamp"].dt.floor('h')
90
 
91
  # Keep only necessary columns
92
  df = df[["timestamp", "Net_Sales_CY"]]