INNER CODE UNIT · Python

load_excel_with_datetime

pgalko/BambooAI · web_app/app.py:421

def load_excel_with_datetime(file_path):
    # Read the Excel file (first sheet)
    df = pd.read_excel(file_path, engine='openpyxl')

    # Function to parse datetime and remove timezone
    def parse_and_remove_tz(series):
        return pd.to_datetime(series, format='%Y-%m-%d %H:%M:%S%z', utc=True).dt.tz_localize(None)

    # Iterate through columns and apply parsing where appropriate
    for col in df.columns:
        # Case 1: Already parsed as datetime (Excel often auto-converts)
        if pd.api.types.is_datetime64_any_dtype(df[col]):
            try:
                df[col] = parse_and_remove_tz(df[col])
            except (ValueError, TypeError):
                pass
        # Case 2: String columns that may contain datetime values
        elif df[col].dtype == 'object':

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…