File size: 1,639 Bytes
c4a2fde
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
"""
测试 stock_basic 接口返回的数据
"""
import tushare as ts
import pandas as pd
import time

TOKEN = "432d609bd03a0283be53b058912cc563eeb5f24092b53f3dcfd2e358"
ts.set_token(TOKEN)
pro = ts.pro_api()

print("=" * 80)
print("Tushare stock_basic - 详细数据测试")
print("=" * 80)

# 等待避免限流
time.sleep(65)

print("\n1. 获取股票基础信息...")
try:
    df = pro.stock_basic(exchange='', list_status='L', 
                         fields='ts_code,symbol,name,area,industry,fullname,enname,cnspell,market,exchange,curr_type,list_status,list_date,delist_date,is_hs')
    
    print(f"\n总股票数: {len(df)}")
    print(f"\n数据列(字段):")
    for i, col in enumerate(df.columns, 1):
        print(f"  {i}. {col}")
    
    print(f"\n\n前5条数据示例:")
    print(df.head().to_string(index=False))
    
    print(f"\n\n数据统计:")
    print(f"  - 沪市股票: {len(df[df['exchange']=='SSE'])}")
    print(f"  - 深市股票: {len(df[df['exchange']=='SZSE'])}")
    print(f"  - 北交所: {len(df[df['exchange']=='BSE'])}")
    print(f"  - 行业数量: {df['industry'].nunique()}")
    print(f"  - 地区数量: {df['area'].nunique()}")
    
    print(f"\n\n行业分布(前10):")
    print(df['industry'].value_counts().head(10).to_string())
    
    print(f"\n\n地区分布(前10):")
    print(df['area'].value_counts().head(10).to_string())
    
    print(f"\n\n上市日期范围:")
    print(f"  最早: {df['list_date'].min()}")
    print(f"  最晚: {df['list_date'].max()}")
    
except Exception as e:
    print(f"ERROR: {e}")

print("\n" + "=" * 80)