INNER CODE UNIT · Python
parse_and_remove_tz
pgalko/BambooAI · web_app/app.py:406
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 vectorized parsing where appropriate
for col in df.columns:
if df[col].dtype == 'object':
# Try to parse the column as datetime
try:
df[col] = parse_and_remove_tz(df[col])
except ValueError:
# If parsing fails, leave the column as is
pass
return df
def load_excel_with_datetime(file_path):
# Read the Excel file (first sheet)
df = pd.read_excel(file_path, engine='openpyxl')