二次重构,加入预设模板

This commit is contained in:
2026-03-09 10:06:21 +08:00
parent 7071b1f730
commit dc9e4bd0ef
77 changed files with 1729 additions and 8760 deletions

View File

@@ -170,8 +170,26 @@ class DataAccessLayer:
# 尝试转换为日期时间
if col_data.dtype == 'object':
try:
pd.to_datetime(col_data.dropna().head(100))
return 'datetime'
sample = col_data.dropna().head(20)
if len(sample) == 0:
pass
else:
# 尝试用常见日期格式解析
date_formats = ['%Y-%m-%d', '%Y/%m/%d', '%Y-%m-%d %H:%M:%S', '%Y/%m/%d %H:%M:%S', '%d/%m/%Y', '%m/%d/%Y']
parsed = False
for fmt in date_formats:
try:
pd.to_datetime(sample, format=fmt)
parsed = True
break
except (ValueError, TypeError):
continue
if not parsed:
# 最后尝试自动推断,但用 infer_datetime_format
pd.to_datetime(sample, format='mixed', dayfirst=False)
parsed = True
if parsed:
return 'datetime'
except:
pass