a-share-code-converter


توضیحات

A lightweight Python utility to convert A-share stock codes to various formats
ویژگی مقدار
سیستم عامل OS Independent
نام فایل a-share-code-converter-0.2.2
نام a-share-code-converter
نسخه کتابخانه 0.2.2
نگهدارنده []
ایمیل نگهدارنده []
نویسنده xTbwOw
ایمیل نویسنده xTbwOw <tomtang0619@gmail.com>
آدرس صفحه اصلی https://github.com/xTbwOw/a_share_code_converter
آدرس اینترنتی https://pypi.org/project/a-share-code-converter/
مجوز MIT License Copyright (c) 2025 xTbwOw Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# A-Share Code Converter `a-share-code-converter` is a lightweight Python utility that helps you normalize and convert Chinese A-share stock codes between various formats. It supports: - Conversion to pure integer codes (e.g., `600519`) - Conversion to zero-padded string codes (e.g., `"600519"`) - Conversion to suffixed formats indicating exchanges (e.g., `"600519.SH"`) The converter supports multiple input types, including: - Python `list` - NumPy arrays - `pandas.Series` - `polars.Series` ## 📦 Installation ```bash pip install a-share-code-converter ``` ## 🚀 Usage The `CodeConverter` class provides the following key methods: ### 1. `CodeConverter.to_int(codes)` Converts various code formats (e.g. `"600519.SH"`, `"000001"`, `430047`) into **pure 6-digit integers**. - ✅ Strips suffixes like `.SH`, `.SZ`, `.BJ` - ✅ Works with `list`, `numpy.ndarray`, `pandas.Series`, `polars.Series` ```python from a_share_code_converter import CodeConverter codes = ["600519", "000001.SZ", "430047.BJ", 2415] CodeConverter.to_int(codes) # Output: [600519, 1, 430047, 2415] ``` ### `2. CodeConverter.to_str(codes)` Converts input to zero-padded 6-digit string format without any suffix. ✅ Ensures all codes are 6-character strings like '000001', '600519' ```python CodeConverter.to_str(codes) # Output: ['600519', '000001', '430047', '002415'] ``` ### 3. `CodeConverter.to_suffix(codes)` Converts codes to full format with market suffix, e.g., '600519.SH'. - ✅ Based on numeric code ranges: - .SZ: 000000–399999 - .SH: 600000–699999 - .BJ: 400000–499999, 800000–899999 ```python CodeConverter.to_suffix(codes) # Output: ['600519.SH', '000001.SZ', '430047.BJ', '002415.SZ'] ``` ### 4. `CodeConverter.convert(codes, to)` A unified entry point to perform conversion. Choose target format via to parameter: | `to` value | Result | | ---------- | ------------------------------------- | | `'int'` | Integer codes (`int` or `np.int64`) | | `'str'` | 6-digit zero-padded string codes | | `'suffix'` | 6-digit string with `.SH`/`.SZ`/`.BJ` | ```python CodeConverter.convert(codes, to='int') # Output: [600519, 1, 430047, 2415] CodeConverter.convert(codes, to='str') # Output: ['600519', '000001', '430047', '002415'] CodeConverter.convert(codes, to='suffix') # Output: ['600519.SH', '000001.SZ', '430047.BJ', '002415.SZ'] ``` ## 🧪 Supported Input Types - list[str | int | float] - numpy.ndarray - pandas.Series - polars.Series All methods will preserve the original type (e.g., return a pandas.Series if input is a pandas.Series).


نیازمندی

مقدار نام
- numpy>=1.20
- pandas>=1.3
- polars>=0.18


زبان مورد نیاز

مقدار نام
>=3.7 Python


نحوه نصب


نصب پکیج whl a-share-code-converter-0.2.2:

    pip install a-share-code-converter.whl


نصب پکیج tar.gz a-share-code-converter-0.2.2:

    pip install a-share-code-converter.tar.gz