siat 3.8.28__py3-none-any.whl → 3.8.35__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
siat/economy2.py CHANGED
@@ -360,6 +360,8 @@ if __name__ =="__main__":
360
360
  indicator="NY.GDP.MKTP.KN"
361
361
  indicator="GC.XPN.TOTL.GD.ZS"
362
362
 
363
+ indicator='GC.GDP.COMP.ZS' # 自制指标
364
+
363
365
  start='2010'; end='2025'; power=3
364
366
 
365
367
  zeroline=False
@@ -380,7 +382,7 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
380
382
  attention_point='',attention_point_area='', \
381
383
  average_value=False, \
382
384
  datatag=False,power=0,graph=True, \
383
- mark_top=True,mark_bottom=True,mark_end=True, \
385
+ mark_start=False,mark_top=False,mark_bottom=False,mark_end=True, \
384
386
  facecolor='whitesmoke',loc='best',maxticks=30):
385
387
  """
386
388
  ===========================================================================
@@ -406,6 +408,15 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
406
408
  输出:图形
407
409
  返回值:数据表
408
410
  """
411
+ import pandas as pd
412
+
413
+ # 自制指标
414
+ sm_ind_list=['GC.GDP.COMP.ZS']
415
+ if indicator in sm_ind_list:
416
+ sm_ind_flag=True
417
+ else:
418
+ sm_ind_flag=False
419
+
409
420
  # 检测指标是否存在,并取得指标名称
410
421
  indicator_name=indicator_name_wb(indicator)
411
422
  if indicator_name == indicator:
@@ -416,11 +427,36 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
416
427
  start,end=start_end_preprocess(start,end)
417
428
 
418
429
  # 下载数据
419
- try:
420
- pricedf=wb.download(indicator=indicator,country=ticker,start=start,end=end)
421
- except:
422
- print(f" #Error(economy_indicator_wb): {indicator} not available for {ticker}")
423
- return None
430
+ if not sm_ind_flag:
431
+ try:
432
+ pricedf=wb.download(indicator=indicator,country=ticker,start=start,end=end)
433
+ except:
434
+ print(f" #Error(economy_indicator_wb): {indicator} not available for {ticker}")
435
+ return None
436
+ elif indicator == 'GC.GDP.COMP.ZS': # 针对自制指标
437
+ indtmp1='NY.GDP.FCST.CN' # Compensation of employees (current LCU),CN无数据!
438
+ indtmp2='NY.GDP.MKTP.CN' # GDP (current LCU)
439
+ try:
440
+ pricetmp1=wb.download(indicator=indtmp1,country=ticker,start=start,end=end)
441
+ except:
442
+ print(f" #Error(economy_indicator_wb): element {indtmp1} not available for {ticker}")
443
+ return None
444
+ try:
445
+ pricetmp2=wb.download(indicator=indtmp2,country=ticker,start=start,end=end)
446
+ except:
447
+ print(f" #Error(economy_indicator_wb): element {indtmp2} not available for {ticker}")
448
+ return None
449
+
450
+ # 算法=indtmp1 / indtmp2 * 100
451
+ pricetmp=pd.merge(pricetmp1,pricetmp2,how='inner',left_on=['country','year'],
452
+ right_on=['country','year'])
453
+ pricetmp[indicator]=pricetmp.apply(lambda x: round(x[indtmp1]/x[indtmp2]*100,2),axis=1)
454
+ pricetmp['country']=pricetmp.index[0][0]
455
+ pricetmp['year']=pricetmp.index
456
+ pricetmp['year']=pricetmp['year'].apply(lambda x: x[1])
457
+
458
+ pricedf=pricetmp[['country','year',indicator]]
459
+ pricedf.reset_index(drop=True,inplace=True)
424
460
 
425
461
  # 是否返回None
426
462
  if pricedf is None:
@@ -432,10 +468,14 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
432
468
  return None
433
469
  # 是否返回数据表但内容均为NaN
434
470
  if pricedf[indicator].isnull().all():
435
- print(f" #Error(economy_indicator_wb): empty data found on {indicator} in {ticker}")
471
+ print(f" #Error(economy_indicator_wb): all empty data found on {indicator} in {ticker}")
436
472
  return None
437
-
438
- pricedf.reset_index(inplace=True)
473
+ # 判断非空值的个数
474
+ if pricedf[indicator].count() == 1:
475
+ print(f" #Warning(economy_indicator_wb): only 1 non-empty data found on {indicator} in {ticker}")
476
+ #return None
477
+
478
+ pricedf.reset_index(drop=True,inplace=True)
439
479
  pricedf.set_index('year',inplace=True)
440
480
  pricedf.rename(columns={indicator:indicator_name},inplace=True)
441
481
  country=pricedf['country'].values[0]
@@ -475,10 +515,6 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
475
515
  erdf3[indicator_name]=erdf3[indicator_name].apply(lambda x: round(x/unit_amount,2))
476
516
 
477
517
  # 绘图
478
- """
479
- if not graph:
480
- return erdf3
481
- """
482
518
  # 判断是否绘制零线
483
519
  if ind_max * ind_min <0:
484
520
  zeroline=True
@@ -510,7 +546,8 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
510
546
  average_value=average_value, \
511
547
  attention_value=attention_value,attention_value_area=attention_value_area, \
512
548
  attention_point=attention_point,attention_point_area=attention_point_area, \
513
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
549
+ mark_top=mark_top,mark_bottom=mark_bottom, \
550
+ mark_start=mark_start,mark_end=mark_end, \
514
551
  facecolor=facecolor,loc=loc,maxticks=30,translate=translate)
515
552
  except Exception as e:
516
553
  # 捕获所有异常
@@ -553,7 +590,7 @@ def economy_mindicators_wb(ticker='CN',indicator=['NY.GDP.MKTP.CN','NY.GDP.MKTP.
553
590
  graph=True,smooth=False,loc='best',facecolor='whitesmoke', \
554
591
  date_range=False,date_freq=False, \
555
592
  annotate=False,annotate_value=False, \
556
- mark_top=False,mark_bottom=False,mark_end=False, \
593
+ mark_start=False,mark_top=False,mark_bottom=False,mark_end=False, \
557
594
  maxticks=30,translate=False):
558
595
  """
559
596
  ===========================================================================
@@ -573,7 +610,7 @@ def economy_mindicators_wb(ticker='CN',indicator=['NY.GDP.MKTP.CN','NY.GDP.MKTP.
573
610
  facecolor:画布背景颜色,默认'whitesmoke'
574
611
  annotate:是否在曲线末端标注,默认否False
575
612
  annotate_value:是否标注曲线末端值,默认否False
576
- mark_top, mark_bottom, mark_end:是否标注最大、最小、末端值,默认否
613
+ mark_start, mark_top, mark_bottom, mark_end:是否标注起始值、最大、最小、末端值,默认否
577
614
  maxticks=30:限制横轴刻度最大数量
578
615
 
579
616
  date_range=False:指定开始结束日期绘图
@@ -720,7 +757,8 @@ def economy_mindicators_wb(ticker='CN',indicator=['NY.GDP.MKTP.CN','NY.GDP.MKTP.
720
757
  attention_value=attention_value,attention_value_area=attention_value_area, \
721
758
  attention_point=attention_point,attention_point_area=attention_point_area, \
722
759
  annotate=annotate,annotate_value=annotate_value, \
723
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end,facecolor=facecolor, \
760
+ mark_start=mark_start,mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
761
+ facecolor=facecolor, \
724
762
  band_area=band_area,loc=loc,maxticks=maxticks,translate=translate)
725
763
 
726
764
  return pricedf
@@ -758,7 +796,7 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
758
796
  band_area='',loc='best', \
759
797
  annotate=False,annotate_value=False, \
760
798
  smooth=False, \
761
- mark_top=True,mark_bottom=True,mark_end=False, \
799
+ mark_start=False,mark_top=True,mark_bottom=True,mark_end=False, \
762
800
  maxticks=30,translate=False):
763
801
  """
764
802
  ===========================================================================
@@ -969,7 +1007,8 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
969
1007
  attention_value=attention_value,attention_value_area=attention_value_area, \
970
1008
  attention_point=attention_point,attention_point_area=attention_point_area, \
971
1009
  annotate=annotate,annotate_value=annotate_value,plus_sign=plus_sign, \
972
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end,facecolor=facecolor, \
1010
+ mark_start=mark_start,mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1011
+ facecolor=facecolor, \
973
1012
  maxticks_enable=False,maxticks=10, \
974
1013
  translate=translate)
975
1014
 
@@ -982,7 +1021,7 @@ def economy_trend2(ticker='CN',indicator='NY.GDP.MKTP.KN', \
982
1021
  start='L10Y',end='today',translate=False, \
983
1022
  attention_value='',attention_value_area='', \
984
1023
  attention_point='',attention_point_area='', \
985
- mark_top=False,mark_bottom=False,mark_end=False, \
1024
+ mark_start=False,mark_top=False,mark_bottom=False,mark_end=False, \
986
1025
  graph=True,facecolor='whitesmoke',loc='best',maxticks=30, \
987
1026
 
988
1027
  zeroline=False,average_value=False, \
@@ -1009,7 +1048,7 @@ def economy_trend2(ticker='CN',indicator='NY.GDP.MKTP.KN', \
1009
1048
  attention_point:横轴关注值或其列表,默认无''
1010
1049
  attention_point_area:横轴关注值区间强调,默认无''
1011
1050
  graph:是否绘图,默认是True
1012
- mark_top, mark_bottom, mark_end:是否标记最高、最低和末端点:默认是True
1051
+ mark_start, mark_top, mark_bottom, mark_end:是否标记开始点、最高、最低和末端点:默认否False
1013
1052
  facecolor:背景颜色,默认'whitesmoke'
1014
1053
  loc:图例位置,默认自动'best'
1015
1054
 
@@ -1082,7 +1121,8 @@ def economy_trend2(ticker='CN',indicator='NY.GDP.MKTP.KN', \
1082
1121
  attention_value_area=attention_value_area, \
1083
1122
  attention_point=attention_point, \
1084
1123
  attention_point_area=attention_point_area, \
1085
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1124
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1125
+ mark_start=mark_start,mark_end=mark_end, \
1086
1126
  graph=graph,facecolor=facecolor,loc=loc,maxticks=maxticks, \
1087
1127
 
1088
1128
  power=power,average_value=average_value, \
@@ -1097,7 +1137,8 @@ def economy_trend2(ticker='CN',indicator='NY.GDP.MKTP.KN', \
1097
1137
  attention_value_area=attention_value_area, \
1098
1138
  attention_point=attention_point, \
1099
1139
  attention_point_area=attention_point_area, \
1100
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1140
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1141
+ mark_start=mark_start,mark_end=mark_end, \
1101
1142
  graph=graph,loc=loc,facecolor=facecolor,maxticks=maxticks, \
1102
1143
  band_area=band_area, \
1103
1144
  annotate=annotate,annotate_value=annotate_value,smooth=smooth, \
@@ -1115,7 +1156,8 @@ def economy_trend2(ticker='CN',indicator='NY.GDP.MKTP.KN', \
1115
1156
  attention_value_area=attention_value_area, \
1116
1157
  attention_point=attention_point, \
1117
1158
  attention_point_area=attention_point_area, \
1118
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1159
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1160
+ mark_start=mark_start,mark_end=mark_end, \
1119
1161
  graph=graph,facecolor=facecolor,loc=loc,maxticks=maxticks, \
1120
1162
 
1121
1163
  annotate=annotate,annotate_value=annotate_value,smooth=smooth, \
@@ -1505,13 +1547,23 @@ def economic_translate(indicator):
1505
1547
  'Exports of goods and services (% of GDP)',
1506
1548
  'Exports of goods and services (% of GDP)'],
1507
1549
 
1550
+ ['NE.IMP.GNFS.CD','进口商品和服务总金额(美元现价)',
1551
+ 'Imports of goods and services (current US$)',
1552
+ 'Imports of goods and services (current US$)'],
1553
+
1554
+ ['NE.EXP.GNFS.CD','出口商品和服务总金额(美元现价)',
1555
+ 'Exports of goods and services (current US$)',
1556
+ 'Exports of goods and services (current US$)'],
1557
+
1508
1558
  ['NE.IMP.GNFS.ZS','进口商品和服务占GDP%',
1509
1559
  'Imports of goods and services (% of GDP)',
1510
1560
  'Imports of goods and services (% of GDP)'],
1511
1561
 
1512
-
1513
-
1514
-
1562
+ ['NE.TRD.GNFS.ZS','国际贸易占GDP%',
1563
+ 'Trade % of GDP',
1564
+ 'Trade % of GDP'],
1565
+ # 用来分析一个国家对国际贸易的依赖程度。
1566
+ # 高贸易占比通常表明一个国家的经济结构以出口和进口为主,而低贸易占比可能表明经济更依赖国内消费或投资。
1515
1567
 
1516
1568
  # 贫困和贫富分化========================================================
1517
1569
  ['SI.POV.GINI','基尼指数',
@@ -1520,8 +1572,60 @@ def economic_translate(indicator):
1520
1572
  # 基尼指数:0-100,用于衡量收入或财富分配的不平等程度。
1521
1573
  # 0表示完全平等,100表示完全不平等。基尼系数高通常意味着贫富差距较大。
1522
1574
  # 注意不是基尼系数(0-1)。
1575
+
1576
+ # 薪酬=================================================================
1577
+ ['GC.GDP.COMP.ZS','劳动者薪酬占GDP%',
1578
+ 'Compensation of employees (% of GDP)',
1579
+ 'Compensation of employees (% of GDP)'],
1580
+ # 自制指标:= GC.XPN.COMP.ZS: Compensation of employees (% of expense)
1581
+ # x GC.XPN.TOTL.GD.ZS: Expense (% of GDP) / 100。
1582
+ # 或 = GC.XPN.COMP.CN: Compensation of employees (current LCU)
1583
+ # / NY.GDP.MKTP.CN: GDP (current LCU) * 100.
1584
+
1585
+ # 储蓄=================================================================
1586
+ ['NY.GNS.ICTR.ZS','国民储蓄总额占GDP%',
1587
+ 'Gross savings (% of GDP)',
1588
+ 'Gross savings (% of GDP)'],
1589
+ # 国民储蓄:一国居民和政府的总储蓄,包含国内储蓄和来自国外的净收入
1590
+ # 包含国际要素:计入来自国外的净要素收入(如投资收益、侨汇)。
1523
1591
 
1592
+ ['NY.GDS.TOTL.ZS','国内储蓄总额占GDP%',
1593
+ 'Gross Domestic Savings (% of GDP)',
1594
+ 'Gross Domestic Savings (% of GDP)'],
1595
+ # 国内储蓄:仅统计国内经济主体(家庭、企业、政府)的储蓄,不包含国外净收入。
1596
+ # 仅限国内:不涉及国际收入或支出。
1597
+
1598
+ # 投资=================================================================
1599
+ ['NE.GDI.TOTL.ZS','总资本形成占GDP%',
1600
+ 'Gross capital formation (% of GDP)',
1601
+ 'Gross capital formation (% of GDP)'],
1602
+ # 又名Gross domestic investment国内总投资,包括政府、企业和家庭的投资
1603
+
1604
+ ['NE.GDI.FTOT.ZS','总固定资本形成占GDP%',
1605
+ 'Gross fixed capital formation (% of GDP)',
1606
+ 'Gross fixed capital formation (% of GDP)'],
1607
+ # 又名Gross domestic fixed investment国内固定资产总投资,包括政府、企业和家庭的投资
1608
+
1609
+ ['BX.KLT.DINV.WD.GD.ZS','外国直接投资净额占GDP%',
1610
+ 'Foreign direct investment, net inflows (% of GDP)',
1611
+ 'Foreign direct investment, net inflows (% of GDP)'],
1612
+ # 等于FDI流入 - FDI流出
1613
+
1614
+ # 政府财政==============================================================
1615
+ ['GC.REV.XGRT.GD.ZS','政府总收入(不含国际赠款)占GDP%',
1616
+ 'Revenue, excluding grant (% of GDP)',
1617
+ 'Revenue, excluding grant (% of GDP)'],
1618
+ # 包括税收和非税收入
1619
+
1620
+ ['SH.XPD.GHED.GD.ZS','政府卫生支出占GDP%',
1621
+ 'Government health expenditure (% of GDP)',
1622
+ 'Domestic general government health expenditure (% of GDP)'],
1623
+ # 包括税收和非税收入
1524
1624
 
1625
+ ['SH.XPD.GHED.CH.ZS','政府卫生支出占当前卫生支出%',
1626
+ 'Government health expenditure (% of health expenditure)',
1627
+ 'Domestic general government health expenditure (% of current health expenditure)'],
1628
+ # 包括税收和非税收入
1525
1629
 
1526
1630
 
1527
1631
 
@@ -1540,7 +1644,7 @@ def economic_translate(indicator):
1540
1644
 
1541
1645
  found=False; result=indicator
1542
1646
  try:
1543
- dict_word=trans_dict[trans_dict['indicator']==indicator]
1647
+ dict_word=trans_dict[trans_dict['indicator']==indicator.upper()]
1544
1648
  found=True
1545
1649
  except:
1546
1650
  #未查到翻译词汇,返回原词