siat 3.8.20__py3-none-any.whl → 3.8.26__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
@@ -170,25 +170,29 @@ if __name__ =="__main__":
170
170
 
171
171
  indicator_name_wb(indicator)
172
172
 
173
- def indicator_name_wb(indicator='NY.GDP.MKTP.KN'):
173
+ def indicator_name_wb(indicator):
174
174
  """
175
175
  ===========================================================================
176
176
  功能:抓取World Bank网页上指标的名称
177
- indicator:WB指标名称,默认'NY.GDP.MKTP.KN'
177
+ indicator:WB指标名称,例如'NY.GDP.MKTP.KN'
178
178
  """
179
+ # 优先查询本地词典
180
+ indicator_name=economic_translate(indicator)
179
181
 
180
- # 构造 API 请求 URL
181
- url = f"https://api.worldbank.org/v2/indicator/{indicator}?format=json"
182
-
183
- # 发送请求
184
- response = requests.get(url)
185
- data = response.json()
186
-
187
- # 提取指标名称
188
- try:
189
- indicator_name = data[1][0]['name']
190
- except:
191
- indicator_name = ''
182
+ # 查询WB网页
183
+ if indicator_name == indicator:
184
+ # 构造 API 请求 URL
185
+ url = f"https://api.worldbank.org/v2/indicator/{indicator}?format=json"
186
+
187
+ # 发送请求
188
+ response = requests.get(url)
189
+ data = response.json()
190
+
191
+ # 提取指标名称
192
+ try:
193
+ indicator_name = data[1][0]['name']
194
+ except:
195
+ indicator_name = indicator
192
196
 
193
197
  return indicator_name
194
198
 
@@ -291,8 +295,8 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
291
295
  """
292
296
  # 检测指标是否存在,并取得指标名称
293
297
  indicator_name=indicator_name_wb(indicator)
294
- if indicator_name == '':
295
- print(f" #Error(economy_indicator_wb): no indicator found for {indicator}")
298
+ if indicator_name == indicator:
299
+ print(f" #Error(economy_indicator_wb): indicator {indicator} not found")
296
300
  return None
297
301
 
298
302
  # 日期具体化
@@ -302,20 +306,20 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
302
306
  try:
303
307
  pricedf=wb.download(indicator=indicator,country=ticker,start=start,end=end)
304
308
  except:
305
- print(f" #Error(economy_indicator_wb): either {indicator} deprecated or {ticker} does not exist")
309
+ print(f" #Error(economy_indicator_wb): {indicator} deprecated or {ticker} not found")
306
310
  return None
307
311
 
308
312
  # 是否返回None
309
313
  if pricedf is None:
310
- print(f" #Error(economy_indicator_wb): no data found on {indicator} for {ticker}")
314
+ print(f" #Error(economy_indicator_wb): no data found on {indicator} in {ticker}")
311
315
  return None
312
316
  # 是否返回空的数据表
313
317
  if len(pricedf) == 0:
314
- print(f" #Error(economy_indicator_wb): zero data found on {indicator} for {ticker}")
318
+ print(f" #Error(economy_indicator_wb): zero data found on {indicator} in {ticker}")
315
319
  return None
316
320
  # 是否返回数据表但内容均为NaN
317
321
  if pricedf[indicator].isnull().all():
318
- print(f" #Error(economy_indicator_wb): all empty data found on {indicator} for {ticker}")
322
+ print(f" #Error(economy_indicator_wb): empty data found on {indicator} in {ticker}")
319
323
  return None
320
324
 
321
325
  pricedf.reset_index(inplace=True)
@@ -325,10 +329,15 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
325
329
  pricedf.sort_index(inplace=True)
326
330
  #pricedf.drop(columns='country',inplace=True)
327
331
 
332
+ # 若不绘图则直接返回数据,不进行数量单位变换,否则后期对比可能产生数量级不一致问题
333
+ if not graph:
334
+ return pricedf
335
+
328
336
  erdf3=pricedf
329
337
 
330
338
  # 换算数量单位
331
- ind_max=erdf3[indicator_name].max(); ind_min=erdf3[indicator_name].min()
339
+ ind_max=erdf3[indicator_name].max()
340
+ ind_min=erdf3[indicator_name].min()
332
341
  ind_median=erdf3[indicator_name].median()
333
342
 
334
343
  kilo=1000; million=kilo * 1000; billion=million * 1000
@@ -347,21 +356,22 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
347
356
  else:
348
357
  unit=''; unit_amount=1
349
358
 
350
- erdf3['unit']=unit
359
+ erdf3['unit']=unit; erdf3['unit_amount']=unit_amount
351
360
 
352
361
  if unit != '':
353
362
  erdf3[indicator_name]=erdf3[indicator_name].apply(lambda x: round(x/unit_amount,2))
354
363
 
355
364
  # 绘图
365
+ """
356
366
  if not graph:
357
367
  return erdf3
358
-
368
+ """
359
369
  # 判断是否绘制零线
360
370
  if ind_max * ind_min <0:
361
371
  zeroline=True
362
372
 
363
- titletxt1=text_lang("经济趋势分析","Economic Trend Analysis")
364
- titletxt=titletxt1+': '+country+', '+indicator_name
373
+ titletxt1=text_lang("经济分析","Economic Analysis")
374
+ titletxt=titletxt1+': '+country_translate(country)+', '+indicator_name
365
375
  if unit != '':
366
376
  titletxt=titletxt+', '+unit
367
377
 
@@ -391,12 +401,12 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
391
401
  facecolor=facecolor,loc=loc,maxticks=30,translate=translate)
392
402
  except Exception as e:
393
403
  # 捕获所有异常
394
- print(f"Error:{e}")
395
- print("Details:")
404
+ print(f" #Error(economy_indicator_wb):{e}")
405
+ print(" Details:")
396
406
  import traceback
397
407
  traceback.print_exc()
398
408
 
399
- return erdf3
409
+ return pricedf
400
410
 
401
411
 
402
412
  #==============================================================
@@ -488,7 +498,7 @@ def economy_mindicators_wb(ticker='CN',indicator=['NY.GDP.MKTP.CN','NY.GDP.MKTP.
488
498
  sys.stdout = self._original_stdout
489
499
 
490
500
  df=pd.DataFrame(); have_data=False
491
- indicator_list=[]; unit_list=[]
501
+ indicator_list=[]
492
502
  for m in measures:
493
503
  print(f" Searching indicator {m} ... ...")
494
504
 
@@ -508,9 +518,7 @@ def economy_mindicators_wb(ticker='CN',indicator=['NY.GDP.MKTP.CN','NY.GDP.MKTP.
508
518
  have_data=True
509
519
 
510
520
  country=dftmp['country'].values[0]
511
- unit=dftmp['unit'].values[0]
512
- unit_list=unit_list+[unit]
513
- dftmp.drop(columns=['country','unit'],inplace=True)
521
+ dftmp.drop(columns=['country'],inplace=True)
514
522
  indicator_name=list(dftmp)[0]
515
523
 
516
524
  if m in band_area:
@@ -523,38 +531,53 @@ def economy_mindicators_wb(ticker='CN',indicator=['NY.GDP.MKTP.CN','NY.GDP.MKTP.
523
531
  else:
524
532
  df=pd.merge(df,dftmp,left_index=True,right_index=True)
525
533
 
526
- if not graph: return df
534
+ # 若不绘图则直接返回数据
535
+ pricedf=df.copy()
536
+ if not graph: return pricedf
527
537
 
528
538
  if not have_data:
529
539
  #print(f" #Error(economy_mindicators_wb): no record found on {indicator} for {ticker}")
530
540
  return None
531
541
 
532
542
  # 绘图
533
- titletxt=text_lang("经济趋势分析","Economic Trend Analysis")+': '+country
543
+ titletxt=text_lang("经济趋势分析","Economic Trend Analysis")+': '+country_translate(country)
534
544
 
535
545
  y_label=text_lang('经济指标',"Economic Indicator")
536
546
  import datetime; todaydt = datetime.date.today()
537
547
  footnote2=text_lang("数据来源:WB/IMF/FRED","Data source: World Bank")+', '+str(todaydt)
538
548
 
539
- one_unit=False
540
- if len(set(unit_list)) == 1: one_unit=True
541
- if one_unit:
542
- x_label=footnote2
543
- if unit != '':
544
- titletxt=titletxt+', '+unit
549
+ # 处理数量级问题
550
+ max_val=min_val=0
551
+ for c in list(df):
552
+ max_tmp=df[c].max(); min_tmp=df[c].min()
553
+ if max_val < max_tmp: max_val = max_tmp
554
+ if min_val > min_tmp: min_val = min_tmp
555
+ ind_median=(max_val + min_val) / 2
556
+
557
+ kilo=1000; million=kilo * 1000; billion=million * 1000
558
+ trillion=billion * 1000; quadrillion=trillion * 1000
559
+
560
+ if ind_median > quadrillion:
561
+ unit=text_lang('单位:千万亿','in Quadrillions'); unit_amount=quadrillion
562
+ elif ind_median > trillion:
563
+ unit=text_lang('单位:万亿','in Trillions'); unit_amount=trillion
564
+ elif ind_median > billion:
565
+ unit=text_lang('单位:十亿','in Billions'); unit_amount=billion
566
+ elif ind_median > million:
567
+ unit=text_lang('单位:百万','in Millions'); unit_amount=million
568
+ elif ind_median > kilo:
569
+ unit=text_lang('单位:千','in Thousands'); unit_amount=kilo
545
570
  else:
546
- #footnote1='The units of '+str(indicator_list)+' are '+str(unit_list)+' respectively'
547
- footnote1=text_lang('注:','Notes: '); indicator_list_len=len(indicator_list)
548
- for ind in indicator_list:
549
- pos=indicator_list.index(ind)
550
- footnote1=footnote1+ind+' '+unit_list[pos]
551
- if (pos < indicator_list_len - 1):
552
- if (pos+1) % 2 != 0:
553
- footnote1=footnote1+', '
554
- else:
555
- footnote1=footnote1+'\n'
571
+ unit=''; unit_amount=1
572
+
573
+ for c in list(df):
574
+ df[c]=df[c].apply(lambda x: round(x/unit_amount,2) if x >= unit_amount else round(x/unit_amount,4))
575
+
576
+ x_label=footnote2
577
+ if unit != '':
578
+ titletxt=titletxt+', '+unit
556
579
 
557
- x_label=footnote1+'\n'+footnote2
580
+ x_label=footnote2
558
581
 
559
582
  axhline_value=0; axhline_label=''
560
583
  above_zero=0; below_zero=0
@@ -573,6 +596,10 @@ def economy_mindicators_wb(ticker='CN',indicator=['NY.GDP.MKTP.CN','NY.GDP.MKTP.
573
596
 
574
597
  # 为避免绘图出错,对空值进行插值
575
598
  df.interpolate(method='linear',limit_direction='both',inplace=True)
599
+
600
+ # 翻译指标名称
601
+ for c in list(df):
602
+ df.rename(columns={c:economic_translate(c)},inplace=True)
576
603
 
577
604
  draw_lines2(df,y_label,x_label,axhline_value,axhline_label,titletxt, \
578
605
  data_label=False,resample_freq='1D',smooth=smooth, \
@@ -583,7 +610,7 @@ def economy_mindicators_wb(ticker='CN',indicator=['NY.GDP.MKTP.CN','NY.GDP.MKTP.
583
610
  mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end,facecolor=facecolor, \
584
611
  band_area=band_area,loc=loc,maxticks=maxticks,translate=translate)
585
612
 
586
- return df
613
+ return pricedf
587
614
 
588
615
 
589
616
  #==============================================================================
@@ -693,28 +720,29 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
693
720
  #from functools import reduce
694
721
 
695
722
  dfs=pd.DataFrame(); have_data=False
696
- country_list=[]; unit_list=[]
723
+ country_list=[]
697
724
  for t in tickers:
698
- print(f" Looking indicator info for {t} ... ...")
725
+ print(f" Looking for {measure} info in {t} ... ...")
699
726
  with HiddenPrints():
700
727
  df_tmp=economy_indicator_wb(ticker=t,indicator=measure, \
701
728
  start=start,end=end,graph=False)
702
729
  if df_tmp is None:
703
- print(f" #Warning(economy_mticker_wb): indicator info not found for {t}")
730
+ print(f" #Warning(economy_mticker_wb): {measure} info not found in {t}")
704
731
  continue
705
732
  if len(df_tmp)==0:
706
- print(f" #Warning(economy_mticker_wb): zero info found for {t} between {start} and {end}")
733
+ print(f" #Warning(economy_mticker_wb): zero info found for {measure} in {t}")
707
734
  continue
708
735
 
709
736
  have_data=True
710
737
 
711
738
  country=df_tmp['country'].values[0]
712
739
  country_list=country_list+[country]
713
- unit=df_tmp['unit'].values[0]
714
- unit_list=unit_list+[unit]
715
- df_tmp.drop(columns=['country','unit'],inplace=True)
740
+ df_tmp.drop(columns=['country'],inplace=True)
716
741
  indicator_name=list(df_tmp)[0]
717
-
742
+
743
+ if DEBUG:
744
+ print(f"DEBUG: t={t}, band_area={band_area}, df_tmp={list(df_tmp)}")
745
+
718
746
  if t in band_area:
719
747
  band_area = [country if x == t else x for x in band_area]
720
748
 
@@ -724,44 +752,61 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
724
752
  dfs=df_tmp
725
753
  else:
726
754
  dfs=pd.concat([dfs,df_tmp],axis=1,join='outer')
727
-
755
+
756
+ # 翻译band_area
757
+ band_area=[country_translate(x) for x in band_area]
758
+
728
759
  if dfs is None:
729
760
  print(f" #Error(economy_mticker_wb): no records found for {measure}")
730
761
  return None
731
762
  if len(dfs)==0:
732
- print(" #Error(economy_mticker_wb): zero records found for {measure}")
763
+ print(f" #Error(economy_mticker_wb): zero records found for {measure}")
733
764
  return None
734
765
 
735
766
  # 若不绘图则返回原始数据
736
- if not graph: return dfs
767
+ pricedf=dfs.copy()
768
+ if not graph: return pricedf
737
769
 
738
770
  if not have_data:
739
771
  #print(f" #Error(economy_mticker_wb): no record found on {indicator} for {ticker}")
740
772
  return None
741
773
 
742
774
  # 绘图
743
- titletxt=text_lang("经济趋势分析","Economic Trend Analysis")+': '+indicator_name
744
- y_label=indicator_name
775
+ titletxt=text_lang("经济分析","Economic Analysis")+': '+indicator_name
776
+ #y_label=indicator_name
777
+ y_label=text_lang("经济指标","Economic Indicator")
745
778
 
746
779
  import datetime; todaydt = datetime.date.today()
747
- footnote2=text_lang("数据来源:WB/IMF/FRED","Data source: World Bank")+', '+str(todaydt)
780
+ footnote2=text_lang("数据来源:WB/IMF/FRED","Data source: WB/IMF/FRED")+', '+str(todaydt)
748
781
 
749
- one_unit=False
750
- if len(set(unit_list)) == 1: one_unit=True
751
- if one_unit:
752
- x_label=footnote2
782
+ # 处理数量级问题
783
+ max_val=min_val=0
784
+ for c in list(dfs):
785
+ max_tmp=dfs[c].max(); min_tmp=dfs[c].min()
786
+ if max_val < max_tmp: max_val = max_tmp
787
+ if min_val > min_tmp: min_val = min_tmp
788
+ ind_median=(max_val + min_val) / 2
789
+
790
+ kilo=1000; million=kilo * 1000; billion=million * 1000
791
+ trillion=billion * 1000; quadrillion=trillion * 1000
792
+
793
+ if ind_median > quadrillion:
794
+ unit=text_lang('单位:千万亿','in Quadrillions'); unit_amount=quadrillion
795
+ elif ind_median > trillion:
796
+ unit=text_lang('单位:万亿','in Trillions'); unit_amount=trillion
797
+ elif ind_median > billion:
798
+ unit=text_lang('单位:十亿','in Billions'); unit_amount=billion
799
+ elif ind_median > million:
800
+ unit=text_lang('单位:百万','in Millions'); unit_amount=million
801
+ elif ind_median > kilo:
802
+ unit=text_lang('单位:千','in Thousands'); unit_amount=kilo
753
803
  else:
754
- footnote1=text_lang('注:','Notes: '); country_list_len=len(country_list)
755
- for ind in country_list:
756
- pos=country_list.index(ind)
757
- footnote1=footnote1+ind+' '+unit_list[pos]
758
- if (pos < country_list_len - 1):
759
- if (pos+1) % 2 != 0:
760
- footnote1=footnote1+', '
761
- else:
762
- footnote1=footnote1+'\n'
763
-
764
- x_label=footnote1+'\n'+footnote2
804
+ unit=''; unit_amount=1
805
+
806
+ for c in list(dfs):
807
+ dfs[c]=dfs[c].apply(lambda x: round(x/unit_amount,2) if x >= unit_amount else round(x/unit_amount,4))
808
+
809
+ x_label=footnote2
765
810
 
766
811
  if preprocess == 'scaling' and scaling_option == 'change%':
767
812
  title_txt2=text_lang("增减幅度%","Change%")
@@ -769,7 +814,7 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
769
814
  axhline_value=0
770
815
  axhline_label="零线"
771
816
  else:
772
- if one_unit and unit != '' and preprocess == 'none':
817
+ if unit != '' and preprocess == 'none':
773
818
  titletxt=titletxt+', '+unit
774
819
 
775
820
  # 为避免出错,对空值进行插值
@@ -801,6 +846,10 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
801
846
  if axhline_label=='':
802
847
  axhline_label='零线'
803
848
 
849
+ # 翻译国家名称
850
+ for c in list(dfs2):
851
+ dfs2.rename(columns={c:country_translate(c)},inplace=True)
852
+
804
853
  draw_lines(dfs2,y_label,x_label,axhline_value,axhline_label,titletxt, \
805
854
  data_label=False,resample_freq='D',smooth=smooth,linewidth=linewidth, \
806
855
  band_area=band_area,loc=loc, \
@@ -811,7 +860,7 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
811
860
  maxticks_enable=False,maxticks=10, \
812
861
  translate=translate)
813
862
 
814
- return dfs2
863
+ return pricedf
815
864
 
816
865
  #==============================================================================
817
866
 
@@ -973,5 +1022,208 @@ def economy_trend2(ticker='CN',indicator='NY.GDP.MKTP.KN', \
973
1022
  #==============================================================================
974
1023
  #==============================================================================
975
1024
  #==============================================================================
1025
+
1026
+
1027
+ def economic_translate(indicator):
1028
+ """
1029
+ ===========================================================================
1030
+ 功能:翻译宏观经济指标术语
1031
+ 参数:
1032
+ indicator: 指标编码,主要是世界银行编码。
1033
+ 注意:部分编码已放弃,可能无数据或无最新数据。
1034
+ 返回值:是否找到,基于语言环境为中文或英文解释。
1035
+ 语言环境判断为check_language()
1036
+
1037
+ 数据结构:['指标编码','中文解释','英文解释']
1038
+ """
1039
+ DEBUG=False
1040
+
1041
+ import pandas as pd
1042
+ trans_dict=pd.DataFrame([
1043
+
1044
+ # NE.CON.PRVT:家庭及NPISH最终消费=======================================
1045
+ ['NE.CON.PRVT.CD','家庭及NPISH最终消费(美元时价)',
1046
+ 'Household & NPISHs Final Consumption (current US$)',
1047
+ 'Households and NPISHs Final consumption expenditure (current US$)'],
1048
+
1049
+ ['NE.CON.PRVT.KD','家庭及NPISH最终消费(2015美元不变价格)',
1050
+ 'Household & NPISHs Final Consumption (constant 2015 US$)',
1051
+ 'Households and NPISHs Final consumption expenditure (constant 2015 US$)'],
1052
+
1053
+ ['NE.CON.PRVT.CN','家庭及NPISH最终消费(本币时价)',
1054
+ 'Household & NPISHs Final Consumption (current LCU)',
1055
+ 'Households and NPISHs Final consumption expenditure (current LCU)'],
1056
+
1057
+ ['NE.CON.PRVT.KN','家庭及NPISH最终消费(本币不变价格)',
1058
+ 'Household & NPISHs Final Consumption (constant LCU)',
1059
+ 'Households and NPISHs Final consumption expenditure (constant LCU)'],
1060
+
1061
+ ['NE.CON.PRVT.ZS','家庭及NPISH最终消费(占GDP%)',
1062
+ 'Household & NPISHs Final Consumption (GDP%)',
1063
+ 'Households and NPISHs Final consumption expenditure (% of GDP)'],
1064
+
1065
+ ['NE.CON.PRVT.KD.ZG','家庭及NPISH最终消费(年增速%)',
1066
+ 'Household & NPISHs Final Consumption (annual % growth)',
1067
+ 'Households and NPISHs Final consumption expenditure (annual % growth)'],
1068
+
1069
+ ['NE.CON.PRVT.PP.CD','家庭及NPISH最终消费(购买力平价,国际美元时价)',
1070
+ 'Household & NPISHs Final Consumption (PPP, current intl $)',
1071
+ 'Households and NPISHs Final consumption expenditure, PPP (current international $)'],
1072
+
1073
+ ['NE.CON.PRVT.PP.KD','家庭及NPISH最终消费(购买力平价,2021国际美元不变价格)',
1074
+ 'Household & NPISHs Final Consumption (PPP, constant 2021 intl $)',
1075
+ 'Households and NPISHs Final consumption expenditure, PPP (constant 2021 international $)'],
1076
+
1077
+ ['NE.CON.PRVT.PC.KD.ZG','人均家庭及NPISH最终消费(年增速%)',
1078
+ 'Household & NPISHs Final Consumption per capita growth (annual %)',
1079
+ 'Households and NPISHs Final consumption expenditure per capita growth (annual %)'],
1080
+
1081
+ ['NE.CON.PRVT.PC.KD','人均家庭及NPISH最终消费(2015美元不变价格)',
1082
+ 'Household & NPISHs Final Consumption per capita (constant 2015 US$)',
1083
+ 'Households and NPISHs Final consumption expenditure per capita (constant 2015 US$)'],
1084
+
1085
+ ['NE.CON.PRVT.CN.AD','家庭及NPISH最终消费(统计口径调整后,本币时价)',
1086
+ 'Household & NPISHs Final Consumption (linked series, current LCU)',
1087
+ 'Households and NPISHs Final consumption expenditure: linked series (current LCU)'],
1088
+
1089
+ # 币种指标:CD=current US$, KD=constant 2015 US$, CN=current LCU
1090
+ # KN=constant LCU, ZS=% of GDP, PC=per capita, PP=PPP
1091
+
1092
+
1093
+
1094
+
1095
+
1096
+
1097
+ ], columns=['indicator','cword','eword','original_eword'])
1098
+
1099
+ found=False; result=indicator
1100
+ try:
1101
+ dict_word=trans_dict[trans_dict['indicator']==indicator]
1102
+ found=True
1103
+ except:
1104
+ #未查到翻译词汇,返回原词
1105
+ pass
1106
+
1107
+ if dict_word is None:
1108
+ found=False
1109
+ elif len(dict_word) == 0:
1110
+ found=False
1111
+
1112
+ if found:
1113
+ lang=check_language()
1114
+
1115
+ if DEBUG:
1116
+ print(f"DEBUG: indicator={indicator}, lang={lang}, dict_word={dict_word}")
1117
+
1118
+ if lang == 'Chinese':
1119
+ result=dict_word['cword'].values[0]
1120
+ else:
1121
+ result=dict_word['eword'].values[0]
1122
+
1123
+ return result
1124
+
1125
+ if __name__=='__main__':
1126
+ indicator='NE.CON.PRVT.CD'
1127
+ indicator='NE.CON.PRVT.KD'
1128
+
1129
+ indicator='NE.CON.PRVT.CN'
1130
+ indicator='NE.CON.PRVT.KN'
1131
+
1132
+ result=economic_translate(indicator)
1133
+ economic_translate(indicator)[1]
1134
+
1135
+ #==============================================================================
1136
+
1137
+
1138
+ def country_translate(country):
1139
+ """
1140
+ ===========================================================================
1141
+ 功能:翻译国家名称
1142
+ 参数:
1143
+ country: 国家名称英文,并非国家代码。
1144
+ 返回值:是否找到,基于语言环境为中文或英文解释。
1145
+ 语言环境判断为check_language()
1146
+
1147
+ 数据结构:['国家名称英文','国家名称中文','国家代码2位','国家代码3位']
1148
+ """
1149
+
1150
+ import pandas as pd
1151
+ trans_dict=pd.DataFrame([
1152
+
1153
+ ['China','中国','CN','CHN'],
1154
+ ['United States','美国','US','USA'],
1155
+ ['Japan','日本','JP','JPN'],
1156
+ ['Germany','德国','DE','DEU'],
1157
+ ['India','印度','IN','IND'],
1158
+ ['Brazil','巴西','BR','BRA'],
1159
+
1160
+ ['France','法国','FR','FRA'],
1161
+ ['United Kingdom','英国','GB','GBR'],
1162
+ ['Russian Federation','俄罗斯','RU','RUS'],
1163
+ ['Canada','加拿大','CA','CAN'],
1164
+ ['Australia','澳大利亚','AU','AUS'],
1165
+ ['Korea, Rep.','韩国','KR','KOR'],
1166
+
1167
+ ['Italy','意大利','IT','ITA'],
1168
+ ['Mexico','墨西哥','MX','MEX'],
1169
+ ['South Africa','南非','ZA','ZAF'],
1170
+ ['Saudi Arabia','沙特阿拉伯','SA','SAU'],
1171
+ ['Indonesia','印度尼西亚','ID','IDN'],
1172
+ ['Turkiye','土耳其','TR','TUR'],
1173
+
1174
+ ['Argentina','阿根廷','AR','ARG'],
1175
+ ['Egypt','埃及','EG','EGY'],
1176
+ ['European Union','欧盟','EU','EUU'],
1177
+ ['Hong Kong SAR, China','中国香港','HK','HKG'],
1178
+ ['Taiwan, China','中国台湾','TW','TWN'],
1179
+ ['World','全球','1W','WLD'],
1180
+
1181
+ ['Singapore','新加坡','SG','SGP'],
1182
+ ['Malaysia','马来西亚','MY','MYS'],
1183
+ ['Thailand','泰国','TH','THA'],
1184
+ ['Israel','以色列','IL','ISR'],
1185
+ ['Vietnam','越南','VN','VNM'],
1186
+ ['Philippines','菲律宾','PH','PHL'],
1187
+ ['Brunei','文莱','BN','BRN'],
1188
+ ['Cambodia','柬埔寨','KH','KHM'],
1189
+
1190
+ ['Laos','老挝','LA','LAO'],
1191
+ ['Myanmar','缅甸','MM','MMR'],
1192
+
1193
+
1194
+
1195
+
1196
+
1197
+ ], columns=['ecountry','ccountry','country code2','country code3'])
1198
+
1199
+ found=False; result=country
1200
+ try:
1201
+ dict_word=trans_dict[trans_dict['ecountry']==country]
1202
+ found=True
1203
+ except:
1204
+ #未查到翻译词汇,返回原词
1205
+ pass
1206
+
1207
+ if dict_word is None:
1208
+ found=False
1209
+ elif len(dict_word) == 0:
1210
+ found=False
1211
+
1212
+ if found:
1213
+ lang=check_language()
1214
+ if lang == 'Chinese':
1215
+ result=dict_word['ccountry'].values[0]
1216
+ else:
1217
+ #result=dict_word['ecountry'].values[0]
1218
+ pass
1219
+
1220
+ return result
1221
+
1222
+ if __name__=='__main__':
1223
+ country='China'
1224
+ country='United States'
1225
+
1226
+ result=country_translate(country)
1227
+
976
1228
  #==============================================================================
977
1229
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: siat
3
- Version: 3.8.20
3
+ Version: 3.8.26
4
4
  Summary: Securities Investment Analysis Tools (siat)
5
5
  Home-page: https://pypi.org/project/siat/
6
6
  Author: Prof. WANG Dehong, International Business School, Beijing Foreign Studies University
@@ -30,7 +30,7 @@ siat/cryptocurrency_test.py,sha256=3AikTNJ7j-HwLGLIYEfyXZ3bLVuLeru9mwiwHQi2SdA,2
30
30
  siat/derivative.py,sha256=qV8n09799eqLc26ojR6vN5n_X-xd7rGwdYjgq-wBih8,41483
31
31
  siat/economy-20230125.py,sha256=vxZZlPnLkh7SpGMVEPLwxjt0yYLSVmdZrO-s2NYLyoM,73848
32
32
  siat/economy.py,sha256=BFVQDxOTbuizyumpCgpZIauH6sqnwUXebpqRMmQCzys,84198
33
- siat/economy2.py,sha256=FOVf5WxKnge3dVEV2CEf--CupXhFtlRUc5k5FUMTD-Q,39857
33
+ siat/economy2.py,sha256=N0Ak2SqTggA7IqgBX2_6KMhmAzTIbgwhHuYDwRKxg8c,49422
34
34
  siat/economy_test.py,sha256=6vjNlPz7W125pJb7simCddobSEp3jmLIMvVkLRZ7zW8,13339
35
35
  siat/esg.py,sha256=GMhaonIKtvOK83rhpQUH5aJt2OL3HQBSVfD__Yw-0oo,19040
36
36
  siat/esg_test.py,sha256=Z9m6GUt8O7oHZSEG9aDYpGdvvrv2AiRJdHTiU6jqmZ0,2944
@@ -144,8 +144,8 @@ siat/valuation_china.py,sha256=CVp1IwIsF3Om0J29RGkyxZLt4n9Ug-ua_RKhLwL9fUQ,69624
144
144
  siat/valuation_market_china_test.py,sha256=gbJ0ioauuo4koTPH6WKUkqcXiQPafnbhU5eKJ6lpdLA,1571
145
145
  siat/var_model_validation.py,sha256=R0caWnuZarrRg9939hxh3vJIIpIyPfvelYmzFNZtPbo,14910
146
146
  siat/yf_name.py,sha256=laNKMTZ9hdenGX3IZ7G0a2RLBKEWtUQJFY9CWuk_fp8,24058
147
- siat-3.8.20.dist-info/LICENSE,sha256=NTEMMROY9_4U1szoKC3N2BLHcDd_o5uTgqdVH8tbApw,1071
148
- siat-3.8.20.dist-info/METADATA,sha256=I4TQUc7XHrSbbQkDRTd2Glcb1hcYKeIyhmUBp3KxMao,8144
149
- siat-3.8.20.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
150
- siat-3.8.20.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
151
- siat-3.8.20.dist-info/RECORD,,
147
+ siat-3.8.26.dist-info/LICENSE,sha256=NTEMMROY9_4U1szoKC3N2BLHcDd_o5uTgqdVH8tbApw,1071
148
+ siat-3.8.26.dist-info/METADATA,sha256=CUxAmvmU5B0Ey8GnKHmRZ1FSRk8gtKT8XsVATp9muws,8144
149
+ siat-3.8.26.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
150
+ siat-3.8.26.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
151
+ siat-3.8.26.dist-info/RECORD,,
File without changes
File without changes