diff --git a/adata/__version__.py b/adata/__version__.py index dd72924..040fb86 100644 --- a/adata/__version__.py +++ b/adata/__version__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -VERSION = (2, 5, 3) +VERSION = (2, 5, 4) PRERELEASE = None # alpha, beta or rc REVISION = None diff --git a/adata/stock/info/stock_index.py b/adata/stock/info/stock_index.py index 5e3774b..4a10834 100644 --- a/adata/stock/info/stock_index.py +++ b/adata/stock/info/stock_index.py @@ -122,7 +122,9 @@ def __index_constituent_baidu(self, index_code=None): result_df = pd.DataFrame(data=data).rename(columns={'code': 'stock_code', 'name': 'short_name'}) result_df['index_code'] = index_code data.clear() - return result_df[self.__INDEX_CONSTITUENT_COLUMN] + result_df = result_df[self.__INDEX_CONSTITUENT_COLUMN] + result_df = result_df.drop_duplicates() + return result_df def __index_constituent_sina(self, index_code=None, wait_time=None): """ diff --git a/adata/stock/market/index_market/market_index_east.py b/adata/stock/market/index_market/market_index_east.py index f75bfe2..3525d55 100644 --- a/adata/stock/market/index_market/market_index_east.py +++ b/adata/stock/market/index_market/market_index_east.py @@ -128,6 +128,8 @@ def get_market_index_current(self, index_code: str = '000001'): result_df['change_pct'] = result_df['change'] / pre_close * 100 result_df = result_df.round(2) result_df['trade_time'] = datetime.datetime.now() + result_df[['open', 'high', 'low', 'price', 'change']] = \ + result_df[['open', 'high', 'low', 'price', 'change']].astype(float) / 100 return result_df diff --git a/adata/stock/market/stock_market/stock_market_east.py b/adata/stock/market/stock_market/stock_market_east.py index 39c9774..3fd9267 100644 --- a/adata/stock/market/stock_market/stock_market_east.py +++ b/adata/stock/market/stock_market/stock_market_east.py @@ -9,8 +9,8 @@ """ import pandas as pd -from adata.common.exception.handler import handler_null +from adata.common.exception.handler import handler_null from adata.common.utils import requests from adata.common.utils.date_utils import get_cur_time from adata.stock.market.stock_market.stock_market_template import StockMarketTemplate @@ -39,7 +39,7 @@ def get_market(self, stock_code: str = '000001', start_date='1990-01-01', end_da se_cid = 1 if stock_code.startswith('6') else 0 start_date = start_date.replace('-', '') if start_date else '19900101' end_date = end_date.replace('-', '') if end_date else get_cur_time("%Y%m%d") - k_type = f"10{k_type}" if k_type < 5 else k_type + k_type = f"10{k_type}" if int(k_type) < 5 else k_type params = {"fields1": "f1,f2,f3,f4,f5,f6", "fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f116", "ut": "7eea3edcaed734bea9cbfc24409ed989", @@ -64,6 +64,7 @@ def get_market(self, stock_code: str = '000001', start_date='1990-01-01', end_da '', "change_pct", "change", "turnover_ratio"]) # 4.清洗数据 df['pre_close'] = df['close'].astype(float) - df['change'].astype(float) + df['pre_close'] = df['pre_close'].round(2) df['trade_time'] = pd.to_datetime(df['trade_date']).dt.strftime('%Y-%m-%d %H:%M:%S') df['trade_date'] = pd.to_datetime(df['trade_date']).dt.strftime('%Y-%m-%d') df['stock_code'] = stock_code @@ -71,9 +72,8 @@ def get_market(self, stock_code: str = '000001', start_date='1990-01-01', end_da 'turnover_ratio', 'pre_close'] df[numeric_columns] = df[numeric_columns].apply(pd.to_numeric) df.reset_index(inplace=True, drop=True) - return df[ - ['trade_time', "trade_date", "open", "close", "high", "low", "volume", "amount", "change_pct", "change", - "turnover_ratio", "pre_close"]] + return df[['stock_code', 'trade_time', "trade_date", "open", "close", "high", "low", "volume", "amount", + "change_pct", "change", "turnover_ratio", "pre_close"]] @handler_null def get_market_min(self, stock_code: str = '000001'): @@ -114,7 +114,7 @@ def get_market_min(self, stock_code: str = '000001'): df[numeric_columns] = df[numeric_columns].apply(pd.to_numeric) df['change'] = df['price'] - pre_close - df['change_pct'] = df['change'] / pre_close*100 + df['change_pct'] = df['change'] / pre_close * 100 df['change_pct'] = df['change_pct'].round(2) df.reset_index(drop=True, inplace=True) return df[self._MARKET_MIN_COLUMNS] @@ -122,4 +122,4 @@ def get_market_min(self, stock_code: str = '000001'): if __name__ == '__main__': print(StockMarketEast().get_market(stock_code='600020', k_type=1, adjust_type=1)) - print(StockMarketEast().get_market_min(stock_code='600020')) + # print(StockMarketEast().get_market_min(stock_code='600020'))