diff --git a/data_platform/updater.py b/data_platform/updater.py index 5bc8366a..fcb54e44 100644 --- a/data_platform/updater.py +++ b/data_platform/updater.py @@ -83,11 +83,13 @@ def fetch_tencent_daily(code: str, start_date: str, end_date: str): return None # kline format: [date, open, close, high, low, volume] or 7 cols with amount - ncols = len(klines[0]) if klines else 6 - if ncols == 7: - df = pd.DataFrame(klines, columns=['date', 'open', 'close', 'high', 'low', 'volume', 'amount']) + df = pd.DataFrame(klines) + ncols = len(df.columns) + if ncols >= 7: + df.columns = ['date', 'open', 'close', 'high', 'low', 'volume', 'amount'][:ncols] else: - df = pd.DataFrame(klines, columns=['date', 'open', 'close', 'high', 'low', 'volume']) + df.columns = ['date', 'open', 'close', 'high', 'low', 'volume'][:ncols] + if 'amount' not in df.columns: df['amount'] = 0.0 for c in ['open', 'close', 'high', 'low', 'volume', 'amount']: df[c] = pd.to_numeric(df[c], errors='coerce').fillna(0)