INNER CODE UNIT · Python

load_json_with_datetime

pgalko/BambooAI · web_app/app.py:467

def load_json_with_datetime(file_path):
    # Read the JSON file
    df = pd.read_json(file_path)

    # 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 (e.g. from epoch timestamps)
        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…