-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
1458 lines (1317 loc) · 68.1 KB
/
main.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import re
import time
import datetime
import numpy as np
import pandas as pd
import altair as alt
import streamlit as st
from streamlit_echarts import st_echarts
from tool import preprocess_choice_data, get_choice_unit_arr
# 数据的列名不要有太多的:,不然会报错: If you are trying to use a column name that contains a colon, prefix it with a backslash; for example "column\:name" instead of "column:name".
class GDP:
def __init__(self):
df = preprocess_choice_data('data/GDP.xlsx')
df = df[(df['指标名称'] >= '1992-01') & (df['指标名称'] <= '2099-01')]
df = df.replace('--', np.nan)
df = df.set_index('指标名称').sort_index()
df['月份'] = [i[-2:] for i in df.index]
df['年份'] = [i[:4] for i in df.index]
self.df = df
def total_plot(self):
pro_df = self.df.loc[:, ['中国:GDP:不变价:累计同比']]
pro_df.columns = [i.replace('中国:', '').replace(':', '-') for i in pro_df.columns]
st.line_chart(pro_df)
def produce_proportion(self):
pro_df = self.df[self.df['月份'] == '12']
pro_df = pro_df.loc[:,
['中国:GDP:现价:第一产业:累计值', '中国:GDP:现价:第二产业:累计值', '中国:GDP:现价:第三产业:累计值']]
pro_df = pro_df.div(pro_df.sum(axis=1).replace(0, np.nan), axis=0)
pro_df.columns = [i.replace('中国:', '').replace(':', '-') for i in pro_df.columns]
st.bar_chart(pro_df)
def produce_change(self):
pro_df = self.df[self.df['月份'] == '12']
pro_df = pro_df.loc[:, ['中国:GDP:不变价:第一产业:当季同比', '中国:GDP:不变价:第二产业:当季同比',
'中国:GDP:不变价:第三产业:当季同比']]
pro_df.columns = [i.replace('中国:', '').replace(':', '-') for i in pro_df.columns]
st.line_chart(pro_df)
def produce_contribute(self):
pro_df = self.df[self.df['月份'] == '12']
pro_df = pro_df.loc[:,
['中国:GDP增长贡献率:第一产业', '中国:GDP增长贡献率:第二产业', '中国:GDP增长贡献率:第三产业']]
pro_df.columns = [i.replace('中国:', '').replace(':', '-') for i in pro_df.columns]
st.bar_chart(pro_df)
def produce_stimulation(self):
pro_df = self.df[self.df['月份'] == '12']
pro_df = pro_df.loc['1992':,
['中国:对GDP增长的拉动:第一产业', '中国:对GDP增长的拉动:第二产业', '中国:对GDP增长的拉动:第三产业']]
pro_df.columns = [i.replace('中国:', '').replace(':', '-') for i in pro_df.columns]
st.bar_chart(pro_df)
def revenue_proportion(self):
pro_df = self.df[self.df['月份'] == '12']
pro_df = pro_df.loc[:, ['中国:GDP:最终消费支出', '中国:GDP:资本形成总额', '中国:GDP:货物和服务净出口']]
pro_df = pro_df.div(pro_df.sum(axis=1).replace(0, np.nan), axis=0)
pro_df.columns = [i.replace('中国:', '').replace(':', '-') for i in pro_df.columns]
st.bar_chart(pro_df)
def revenue_contribute(self):
pro_df = self.df[self.df['月份'] == '12']
pro_df = pro_df.loc[:, ['中国:三大需求对GDP增长的贡献率:最终消费支出:累计值',
'中国:三大需求对GDP增长的贡献率:资本形成总额:累计值',
'中国:三大需求对GDP增长的贡献率:货物和服务净出口:累计值']]
pro_df.columns = [i.replace('中国:三大需求对GDP增长的贡献率:', '').replace(':', '-') for i in pro_df.columns]
st.line_chart(pro_df.dropna())
class PMI:
def __init__(self):
df = preprocess_choice_data('data/PMI.xlsx')
df = df[(df['指标名称'] >= '2000-01') & (df['指标名称'] <= '2099-01')]
df = df.replace('--', np.nan)
df = df.set_index('指标名称').sort_index()
self.df = df
def total_plot(self):
pro_df = self.df.loc[:, ['PMI', '非制造业PMI:商务活动', '综合PMI:产出指数']]
start_date = '2019-01'
pro_df = pro_df.loc[start_date:, :]
st.line_chart(pro_df)
def demand_plot(self):
pro_df = self.df.loc[:, ['PMI:新订单', 'PMI:新出口订单', 'PMI:积压订单']]
start_date = '2019-01'
pro_df = pro_df.loc[start_date:, :]
st.line_chart(pro_df)
def produce_plot(self):
pro_df = self.df.loc[:, ['PMI:新订单', 'PMI:生产']]
start_date = '2019-01'
pro_df = pro_df.loc[start_date:, :]
st.line_chart(pro_df)
def procurement_plot(self):
pro_df = self.df.loc[:, ['PMI:采购量', 'PMI:进口']]
start_date = '2019-01'
pro_df = pro_df.loc[start_date:, :]
st.line_chart(pro_df)
def inventory_plot(self):
pro_df = self.df.loc[:, ['PMI:产成品库存', 'PMI:原材料库存']]
start_date = '2019-01'
pro_df = pro_df.loc[start_date:, :]
st.line_chart(pro_df)
def price_plot(self):
pro_df = self.df.loc[:, ['PMI:购进价格', 'PMI:出厂价格']]
start_date = '2019-01'
pro_df = pro_df.loc[start_date:, :]
st.line_chart(pro_df)
class CPI_PPI:
def __init__(self):
df = preprocess_choice_data('data/CPI+PPI.xlsx')
df = df[(df['指标名称'] >= '2000-01') & (df['指标名称'] <= '2099-01')]
df = df.replace('--', np.nan)
df = df.set_index('指标名称').sort_index()
self.df = df
def total_plot(self):
pro_df = self.df.loc[:, ['CPI:环比', 'PPI:全部工业品:环比']]
start_date = '2000-01'
pro_df = pro_df.loc[start_date:, :]
st.line_chart(pro_df.astype(float))
def cpi_plot(self):
pro_df = self.df.loc[:, ['CPI:环比', 'CPI:食品:环比', 'CPI:非食品:环比']]
start_date = '2000-01'
pro_df = pro_df.loc[start_date:, :]
st.line_chart(pro_df.astype(float))
def ppi_plot(self):
pro_df = self.df.loc[:, ['PPI:全部工业品:环比', 'PPI:生产资料:环比', 'PPI:生活资料:环比']]
start_date = '2000-01'
pro_df = pro_df.loc[start_date:, :]
st.line_chart(pro_df.astype(float))
class TRSCG:
def __init__(self):
df = preprocess_choice_data('data/社零.xlsx')
df = df[(df['指标名称'] >= '2000-01') & (df['指标名称'] <= '2099-01')]
df = df.replace('--', np.nan)
df = df.set_index('指标名称').sort_index()
rate_df = df.pct_change(10)
rate_df.columns = [i + '%' for i in rate_df.columns]
df = pd.concat([df, rate_df], axis=1)
self.df = df
def total_plot(self):
pro_df = self.df.loc[:, ['社会消费品零售总额:当月值', '社会消费品零售总额:当月值%']].reset_index()
pro_df.columns = [i.replace(':', '-') for i in pro_df.columns]
start_date = '2000-01'
pro_df = pro_df.loc[start_date:, :]
bars = alt.Chart(pro_df).mark_bar().encode(
x='指标名称',
y='社会消费品零售总额-当月值'
)
line = alt.Chart(pro_df).mark_line(color='red').encode(
x='指标名称',
y='社会消费品零售总额-当月值%'
)
# 将柱状图和折线图组合在一起
chart = alt.layer(bars, line).resolve_scale(y='independent')
st.altair_chart(chart, use_container_width=True)
def season_plot(self):
start_date = '2019-01'
pro_df = self.df.loc[start_date:, ['社会消费品零售总额:当月值']]
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df['年份'] = [i[:4] for i in pro_df.index]
pro_df = pro_df.pivot(index=['月份'], columns=['年份'], values='社会消费品零售总额:当月值')
st.line_chart(pro_df.astype(float))
def automobile_proportion(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:,
['社会消费品零售总额:当月值', '社会消费品零售总额:除汽车以外的消费品零售额:当月值']]
pro_df.columns = ['总额', '除汽车']
pro_df = pro_df.div(pro_df['总额'], axis=0)
pro_df['汽车'] = pro_df['总额'] - pro_df['除汽车']
st.bar_chart(pro_df.iloc[:, 1:].astype(float))
def automobile_increase(self):
start_date = '2000-01'
pro_df = self.df.loc[:, ['社会消费品零售总额:当月值', '社会消费品零售总额:除汽车以外的消费品零售额:当月值']]
pro_df.columns = ['总额', '除汽车']
pro_df['汽车'] = pro_df['总额'] - pro_df['除汽车']
pro_df = pro_df.pct_change(10).loc[start_date:]
st.line_chart(pro_df.astype(float))
def goods_food_proportion(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, ['社会消费品零售总额:商品零售:当月值', '社会消费品零售总额:餐饮收入:当月值']]
pro_df.columns = ['商品零售', '餐饮收入']
pro_df = pro_df.div(pro_df.sum(axis=1), axis=0)
st.bar_chart(pro_df.astype(float))
def goods_food_increase(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, ['社会消费品零售总额:当月值%', '社会消费品零售总额:商品零售:当月值%',
'社会消费品零售总额:餐饮收入:当月值%']]
pro_df.columns = ['总额', '商品零售', '餐饮收入']
st.line_chart(pro_df.astype(float))
def area_proportion(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, ['社会消费品零售总额:城镇:当月值', '社会消费品零售总额:农村:当月值']]
pro_df.columns = ['城镇', '农村']
pro_df = pro_df.div(pro_df.sum(axis=1).replace(0, np.nan), axis=0)
st.bar_chart(pro_df.astype(float))
def area_increase(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:,
['社会消费品零售总额:当月值%', '社会消费品零售总额:城镇:当月值%', '社会消费品零售总额:农村:当月值%']]
pro_df.columns = ['总额', '城镇', '农村']
st.line_chart(pro_df.astype(float))
def online_proportion(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, ['社会消费品零售总额:当月值', '社会消费品零售总额:网上零售:当月值']]
pro_df.columns = ['总额', '网上零售']
pro_df = pro_df.div(pro_df['总额'].replace(0, np.nan), axis=0)
pro_df['网下零售'] = pro_df['总额'] - pro_df['网上零售']
st.bar_chart(pro_df.iloc[:, 1:].astype(float))
def online_increase(self):
start_date = '2000-01'
pro_df = self.df.loc[:, ['社会消费品零售总额:当月值', '社会消费品零售总额:网上零售:当月值']]
pro_df.columns = ['总额', '网上零售']
pro_df['网下零售'] = pro_df['总额'] - pro_df['网上零售']
pro_df = pro_df.pct_change(10).loc[start_date:]
st.line_chart(pro_df.astype(float))
def limit_proportion(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, ['社会消费品零售总额:当月值', '限额以上企业消费品零售总额:当月值']]
pro_df.columns = ['总额', '限额']
pro_df = pro_df.div(pro_df['总额'].replace(0, np.nan), axis=0)
pro_df['非限额'] = pro_df['总额'] - pro_df['限额']
st.bar_chart(pro_df.iloc[:, 1:].astype(float))
def limit_increase(self):
start_date = '2000-01'
pro_df = self.df.loc[:, ['社会消费品零售总额:当月值', '限额以上企业消费品零售总额:当月值']]
pro_df.columns = ['总额', '限额']
pro_df['非限额'] = pro_df['总额'] - pro_df['限额']
pro_df = pro_df.pct_change(10).loc[start_date:]
st.line_chart(pro_df.astype(float))
class ExportBasic:
def __init__(self):
df = preprocess_choice_data('data/进出口基本.xlsx')
df = df[(df['指标名称'] >= '2000-01') & (df['指标名称'] <= '2099-01')]
df = df.replace('--', np.nan)
df = df.set_index('指标名称').sort_index()
self.df = df
def total_plot(self):
start_date = '2013-01'
pro_df = self.df.loc[start_date:,
['出口金额:当月同比', '进口金额:当月同比', '出口金额:人民币:当月同比', '进口金额:人民币:当月同比']]
st.line_chart(pro_df.dropna().astype(float))
def amount_plot(self):
start_date = '2013-01'
pro_df = self.df.loc[start_date:,
['出口金额:当月值', '进口金额:当月值', '进出口金额:当月值', '贸易顺差:当月值']].astype(float)
pro_df['进出口金额:当月值'] = pro_df['进出口金额:当月值']
st.line_chart(pro_df)
def output_season_plot(self):
start_date = '2019-01'
pro_df = self.df.loc[start_date:, ['出口金额:当月同比']]
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df['年份'] = [i[:4] for i in pro_df.index]
pro_df = pro_df.pivot(index=['月份'], columns=['年份'], values='出口金额:当月同比')
st.line_chart(pro_df)
def input_season_plot(self):
start_date = '2019-01'
pro_df = self.df.loc[start_date:, ['进口金额:当月同比']]
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df['年份'] = [i[:4] for i in pro_df.index]
pro_df = pro_df.pivot(index=['月份'], columns=['年份'], values='进口金额:当月同比')
st.line_chart(pro_df)
class ExportCountry:
def __init__(self):
path = 'data/进出口区域.xlsx'
df = preprocess_choice_data(path)
df = df[(df['指标名称'] >= '2000-01') & (df['指标名称'] <= '2099-01')]
df = df.replace('--', np.nan)
df = df.set_index('指标名称').sort_index()
input_df = df.loc[:, df.columns.str.contains('进口')]
input_df.columns = [i.split(':')[0] for i in input_df.columns]
output_df = df.loc[:, df.columns.str.contains('出口')]
output_df.columns = [i.split(':')[0] for i in output_df.columns]
self.input_df = input_df
self.output_df = output_df
def output_portion(self):
options = self.output_df.index.tolist()
date = st.select_slider("请选择想要查询的日期", options=options, key='output_portion', value=options[-1])
st.write("当前选择的日期是:", date)
# 创建2个空的容器
slider_container = st.empty()
chart_container = st.empty()
run = st.button("播放动画", key='output_run', type='primary')
def run_plot(date, object):
selected_df = self.output_df.loc[date].reset_index()
chart1 = alt.Chart(selected_df).mark_arc().encode(
theta=alt.Theta(field=selected_df.columns[1], type="quantitative"),
color=alt.Color(field=selected_df.columns[0], type="nominal"),
)
object.altair_chart(chart1, theme="streamlit", use_container_width=True)
if run:
for i in options:
time.sleep(0.1)
slider_container.select_slider("Select Date", options=options, value=i, key=i)
run_plot(i, chart_container)
else:
run_plot(date, st)
def input_portion(self):
options = self.input_df.index.tolist()
date = st.select_slider("请选择想要查询的日期", options=options, key='input_portion', value=options[-1])
st.write("当前选择的日期是:", date)
# 创建2个空的容器
slider_container = st.empty()
chart_container = st.empty()
run = st.button("播放动画", key='input_run', type='primary')
def run_plot(date, object):
selected_df = self.input_df.loc[date].reset_index()
chart2 = alt.Chart(selected_df).mark_arc().encode(
theta=alt.Theta(field=selected_df.columns[1], type="quantitative"),
color=alt.Color(field=selected_df.columns[0], type="nominal"),
)
object.altair_chart(chart2, theme="streamlit", use_container_width=True)
if run:
for i in options:
time.sleep(0.1)
slider_container.select_slider("Select Date", options=options, value=i, key=i)
run_plot(i, chart_container)
else:
run_plot(date, st)
def output_trend(self):
start_date = '2000-01'
plot_df = self.output_df
plot_df['年份'] = [i[:4] for i in plot_df.index]
plot_df = plot_df.groupby(['年份']).sum()
plot_df = plot_df.div(plot_df.sum(axis=1), axis=0)
plot_df = plot_df.loc[start_date:, plot_df.iloc[0].sort_values().tail(5).index]
st.line_chart(plot_df.dropna().astype(float) * 100)
def input_trend(self):
start_date = '2000-01'
plot_df = self.input_df
plot_df['年份'] = [i[:4] for i in plot_df.index]
plot_df = plot_df.groupby(['年份']).sum()
plot_df = plot_df.div(plot_df.sum(axis=1), axis=0)
plot_df = plot_df.loc[start_date:, plot_df.iloc[0].sort_values().tail(5).index]
st.line_chart(plot_df.dropna().astype(float) * 100)
class FixedAssetInvest:
def __init__(self):
df = preprocess_choice_data('data/固定资产投资.xlsx')
df = df[(df['指标名称'] >= '2000-01') & (df['指标名称'] <= '2099-01')]
df = df.replace('--', np.nan)
df = df.set_index('指标名称').sort_index()
self.df = df
def total_plot(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='fixed_asset_total_plot')
pro_df = self.df.loc[start_date:, :]
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[:, ['固定资产投资完成额:累计值', '固定资产投资完成额:累计同比']].reset_index()
pro_df.columns = [i.replace(':', '-') for i in pro_df.columns]
bars = alt.Chart(pro_df).mark_bar().encode(
x='指标名称',
y='固定资产投资完成额-累计值'
)
line = alt.Chart(pro_df).mark_line(color='red').encode(
x='指标名称',
y='固定资产投资完成额-累计同比'
)
# 将柱状图和折线图组合在一起
chart = alt.layer(bars, line).resolve_scale(y='independent')
st.altair_chart(chart, use_container_width=True)
def season_plot(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, ['固定资产投资完成额:累计同比']]
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df['年份'] = [i[:4] for i in pro_df.index]
pro_df = pro_df.pivot(index=['月份'], columns=['年份'], values='固定资产投资完成额:累计同比')
print(pro_df)
pro_df = pro_df.astype(float)
st.line_chart(pro_df)
def construct_type(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='construct_type')
pro_df = self.df.loc[start_date:, :]
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[:, ['固定资产投资完成额:新建:累计同比', '固定资产投资完成额:扩建:累计同比',
'固定资产投资完成额:改建:累计同比']]
pro_df.columns = ['新建', '扩建', '改建']
pro_df = pro_df.astype(float)
st.line_chart(pro_df)
def portion(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='portion')
pro_df = self.df.loc[start_date:, :]
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[:,
['固定资产投资完成额:建筑安装工程:累计同比', '固定资产投资完成额:设备工器具购置:累计同比',
'固定资产投资完成额:其他费用:累计同比']]
pro_df.columns = ['建筑安装工程', '设备工器具购置', '其他费用']
pro_df = pro_df.astype(float)
st.line_chart(pro_df)
def industry(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='industry')
pro_df = self.df.loc[start_date:, :]
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[:, ['固定资产投资完成额:第一产业:累计同比', '固定资产投资完成额:第二产业:累计同比',
'固定资产投资完成额:第三产业:累计同比']]
pro_df.columns = ['第一产业', '第二产业', '第三产业']
pro_df = pro_df.astype(float)
st.line_chart(pro_df)
def state_owned(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='state_owned')
pro_df = self.df.loc[start_date:, :]
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[:, ['民间固定资产投资完成额:累计同比', '固定资产投资完成额:国有控股企业:累计同比']]
pro_df.columns = ['民间', '国有控股企业']
pro_df = pro_df.astype(float)
st.line_chart(pro_df)
class FinancingMoney:
def __init__(self):
df = preprocess_choice_data('data/社融货币.xlsx')
df = df[(df['指标名称'] >= '2000-01') & (df['指标名称'] <= '2099-01')]
df = df.replace('--', np.nan)
df = df.set_index('指标名称').sort_index()
df['社融增量:同比增速'] = df['社会融资增量:当月值'].pct_change(12)
df['社融存量:同比增速'] = df['社会融资规模存量'].pct_change(12)
self.df = df
def financing_plot(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, ['社会融资增量:当月值', '社融增量:同比增速']].reset_index()
pro_df.columns = [i.replace(':', '-') for i in pro_df.columns]
bars = alt.Chart(pro_df).mark_bar().encode(
x='指标名称',
y='社会融资增量-当月值'
)
line = alt.Chart(pro_df).mark_line(color='red').encode(
x='指标名称',
y='社融增量-同比增速'
)
# 将柱状图和折线图组合在一起
chart = alt.layer(bars, line).resolve_scale(y='independent')
st.altair_chart(chart, use_container_width=True)
def season_plot(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, ['社会融资增量:当月值']]
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df['年份'] = [i[:4] for i in pro_df.index]
pro_df = pro_df.pivot(index=['月份'], columns=['年份'], values='社会融资增量:当月值')
pro_df = pro_df.astype(float)
st.line_chart(pro_df)
def financing_portion(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
pro_df = pro_df.loc[:,
['社会融资增量:新增人民币贷款:当月值', '社会融资增量:新增外币贷款(按人民币计):当月值',
'社会融资增量:新增委托贷款:当月值', '社会融资增量:新增信托贷款:当月值',
'社会融资增量:新增未贴现银行承兑汇票:当月值',
'社会融资增量:企业债券融资:当月值', '社会融资增量:非金融企业境内股票融资:当月值',
'社会融资增量:政府债券:当月值', '社会融资增量:贷款核销:当月值',
'社会融资增量:存款类金融机构资产支持证券:当月值',
]]
pro_df.columns = ['人民币贷款', '外币贷款', '委托贷款', '信托贷款', '未贴现银行承兑汇票', '企业债券融资',
'企业股票融资', '政府债券', '贷款核销', '存款机构ABS']
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def increment_loan(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
pro_df = pro_df.loc[:,
['金融机构:新增人民币贷款:居民户:短期:当月值', '金融机构:新增人民币贷款:居民户:中长期:当月值',
'金融机构:新增人民币贷款:非金融性公司及其他部门:短期:当月值',
'金融机构:新增人民币贷款:非金融性公司及其他部门:中长期:当月值',
'金融机构:新增人民币贷款:非金融性公司及其他部门:票据融资:当月值',
]]
pro_df.columns = ['居民户:短期', '居民户:中长期', '企业:短期', '企业:中长期', '企业:票据融资', ]
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def off_sheet(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
pro_df = pro_df.loc[:,
['社会融资增量:新增委托贷款:当月值', '社会融资增量:新增信托贷款:当月值', ]]
pro_df.columns = ['新增委托贷款', '新增信托贷款']
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def direct_financing(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
pro_df = pro_df.loc[:,
['社会融资增量:企业债券融资:当月值', '社会融资增量:非金融企业境内股票融资:当月值']]
pro_df.columns = ['企业债券融资', '企业股票融资']
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def financing_other(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
pro_df = pro_df.loc[:,
['社会融资增量:政府债券:当月值', '社会融资增量:贷款核销:当月值',
'社会融资增量:存款类金融机构资产支持证券:当月值']]
pro_df.columns = ['政府债券', '贷款核销', '存款机构ABS']
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def money_plot(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
c1, c2 = st.columns([1, 1])
selected_start_date = c1.selectbox('开始日期', options=pro_df.index.tolist(), index=len(pro_df) - 24,
key='start_money_plot')
selected_end_date = c2.selectbox('结束日期', options=pro_df.index.tolist(), index=len(pro_df)-1,
key='end_money_plot')
pro_df = pro_df.loc[selected_start_date:selected_end_date, :]
pro_df = pro_df.loc[:,
['M0:同比', 'M1:同比', 'M2:同比']]
# pro_df.columns = ['M0同', '贷款核销', '存款机构ABS']
st.line_chart(pro_df.dropna().astype(float))
def money_scissors(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
c1, c2 = st.columns([1, 1])
selected_start_date = c1.selectbox('开始日期', options=pro_df.index.tolist(), index=len(pro_df) - 24,
key='start_money_scissors')
selected_end_date = c2.selectbox('结束日期', options=pro_df.index.tolist(), index=len(pro_df)-1,
key='end_money_scissors')
pro_df = pro_df.loc[selected_start_date:selected_end_date, :]
pro_df['M1-M2增速'] = pro_df['M1:同比'] - pro_df['M2:同比']
pro_df['社融-M2增速'] = pro_df['社融存量:同比增速'] * 100 - pro_df['M2:同比']
pro_df = pro_df.loc[:, ['M1-M2增速', '社融-M2增速']]
st.line_chart(pro_df.dropna().astype(float))
class Fiscal:
def __init__(self):
df = preprocess_choice_data('data/财政.xlsx')
df = df[(df['指标名称'] >= '2000-01') & (df['指标名称'] <= '2099-01')]
df = df.replace('--', np.nan)
df = df.set_index('指标名称').sort_index()
self.df = df
def central_budget_revenue(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='central_budget_revenue')
pro_df = self.df.loc[start_date:, :]
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[:, ['一般公共预算收入:中央财政:累计值', '一般公共预算收入:地方财政:累计值']]
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def tax_budget_revenue(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='tax_budget_revenue')
pro_df = self.df.loc[start_date:, :]
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[:, ['一般公共预算收入:税收收入:累计值', '一般公共预算收入:非税收入:累计值']]
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def tax_detail_revenue(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='tax_detail_revenue')
pro_df = self.df.loc[start_date:, :]
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[:, ['一般公共预算收入:税收收入:增值税:累计值', '一般公共预算收入:税收收入:消费税:累计值',
'一般公共预算收入:税收收入:海关代征增值税和消费税:累计值',
'一般公共预算收入:税收收入:外贸企业出口退税:累计值',
'一般公共预算收入:税收收入:营业税:累计值',
'一般公共预算收入:税收收入:企业所得税:累计值',
'一般公共预算收入:税收收入:个人所得税:累计值',
'一般公共预算收入:税收收入:资源税:累计值',
'一般公共预算收入:税收收入:城市维护建设税:累计值',
'一般公共预算收入:税收收入:房产税:累计值',
'一般公共预算收入:税收收入:印花税:累计值',
'一般公共预算收入:税收收入:证券交易印花税:累计值',
'一般公共预算收入:税收收入:城镇土地使用税:累计值',
'一般公共预算收入:税收收入:土地增值税:累计值',
'一般公共预算收入:税收收入:车辆购置税:累计值', '一般公共预算收入:税收收入:关税:累计值',
'一般公共预算收入:税收收入:契税:累计值']]
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def central_budget_expenditure(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='central_budget_expenditure')
pro_df = self.df.loc[start_date:, :]
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[:, ['一般公共预算支出:中央财政:累计值', '一般公共预算支出:地方财政:累计值']]
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def total_detail_expenditure(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='total_detail_expenditure')
pro_df = self.df.loc[start_date:, :]
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[:,
['一般公共预算支出:一般公共服务:累计值', '一般公共预算支出:教育:累计值',
'一般公共预算支出:科学技术:累计值',
'一般公共预算支出:文化体育与传媒:累计值', '一般公共预算支出:社会保障和就业:累计值',
'一般公共预算支出:卫生健康:累计值',
'一般公共预算支出:节能环保:累计值', '一般公共预算支出:城乡社区事务:累计值',
'一般公共预算支出:农林水事务:累计值',
'一般公共预算支出:交通运输:累计值', ]]
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def budget_deficit(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='budget_deficit')
pro_df = self.df.loc[start_date:, :]
pro_df['预算赤字'] = pro_df['一般公共预算支出:累计值'] - pro_df['一般公共预算收入:累计值']
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[:, ['预算赤字']]
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def government_fund(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='government_fund')
pro_df = self.df.loc[start_date:, :]
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[:, ['中央政府性基金收入:累计值', '地方政府性基金本级收入:累计值']]
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def land_grand_fee(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='land_grand_fee')
pro_df = self.df.loc[start_date:, :]
pro_df['其他基金收入'] = pro_df['全国政府性基金收入:累计值'] - pro_df['国有土地使用权出让收入:累计值']
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[:, ['其他基金收入', '国有土地使用权出让收入:累计值']]
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def exchange_fee(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, ['交易印花税:当月值', '股票成交金额:当月值']]
c1, c2 = st.columns([1, 1])
selected_start_date = c1.selectbox('开始日期', options=pro_df.index.tolist(), index=len(pro_df) - 24,
key='start_exchange_fee')
selected_end_date = c2.selectbox('结束日期', options=pro_df.index.tolist(), index=len(pro_df)-1,
key='end_exchange_fee')
pro_df = pro_df.loc[selected_start_date:selected_end_date, :].reset_index().dropna()
pro_df.columns = [i.replace(':', '-') for i in pro_df.columns]
bars = alt.Chart(pro_df).mark_bar().encode(
x='指标名称',
y='股票成交金额:当月值'.replace(':', '-')
)
line = alt.Chart(pro_df).mark_line(color='red').encode(
x='指标名称',
y='交易印花税:当月值'.replace(':', '-')
)
# 将柱状图和折线图组合在一起
chart = alt.layer(bars, line).resolve_scale(y='independent')
st.altair_chart(chart, use_container_width=True)
class PopulationEnployment:
def __init__(self):
df = preprocess_choice_data('data/人口就业.xlsx')
df = df[(df['指标名称'] >= '2000-01') & (df['指标名称'] <= '2099-01')]
df = df.replace('--', np.nan)
df = df.set_index('指标名称').sort_index()
self.df = df
def total_unemployment_rate(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
pro_df = pro_df.loc[:, ['城镇调查失业率:全国']]
pro_df.columns = [i.replace(':', '-') for i in pro_df.columns]
st.line_chart(pro_df.dropna().astype(float))
def age_unemployment_rate(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :].copy()
pro_df.columns = [i.replace(':', '-').replace("(停止)", "") for i in pro_df.columns]
pro_df = pro_df.loc[:, ['全国16-24岁人口城镇调查失业率', '全国25-59岁人口城镇调查失业率']]
st.line_chart(pro_df.dropna().astype(float))
def not_student_age_unemployment_rate(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :].copy()
pro_df.columns = [i.replace(':', '-').replace("(停止)", "") for i in pro_df.columns]
pro_df = pro_df.loc[:,
['城镇调查失业率-不包含在校生的16至24岁劳动力', '城镇调查失业率-不包含在校生的25至29岁劳动力',
'城镇调查失业率-不包含在校生的30至59岁劳动力']]
st.line_chart(pro_df.dropna().astype(float))
def eductaion_unemployment_rate(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :].copy()
pro_df.columns = [i.replace(':', '-').replace("(停止)", "") for i in pro_df.columns]
print(pro_df.columns)
pro_df = pro_df.loc[:, ['全国25-59岁劳动力失业率-初中及以下学历', '全国25-59岁劳动力失业率-高中学历',
'全国25-59岁劳动力失业率-大专学历', '全国25-59岁劳动力失业率-本科及以上学历']]
st.line_chart(pro_df.dropna().astype(float))
def birth_death_rate(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
pro_df = pro_df.loc[:, ['人口出生率', '人口死亡率', '人口自然增长率']]
st.line_chart(pro_df.dropna().astype(float))
def increment_population(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
pro_df = pro_df.loc[:, ['总人口:城镇:增减', '总人口:乡村:增减']]
st.line_chart(pro_df.dropna().astype(float))
def graduation_population(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
pro_df = pro_df.loc[:, ['全国:高等学校毕业生数:本科']]
pro_df.columns = [i.replace(':', '-') for i in pro_df]
st.line_chart(pro_df.dropna().astype(float))
class Forex:
def __init__(self):
df = preprocess_choice_data('data/外汇.xlsx')
df = df[(df['指标名称'] >= '2000-01') & (df['指标名称'] <= '2099-01')]
df = df.replace('--', np.nan)
df = df.set_index('指标名称').sort_index()
self.df = df
def total_forex(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
pro_df = pro_df.loc[:, ['货币当局:国外资产:外汇', '货币当局:对其他存款性公司债权', '货币当局:储备货币']]
pro_df['外汇债权合计'] = pro_df["货币当局:国外资产:外汇"] + pro_df["货币当局:对其他存款性公司债权"]
pro_df.columns = [i.replace(':', '-') for i in pro_df.columns]
st.line_chart(pro_df.dropna().astype(float))
def total_bank_exchange(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
pro_df = pro_df.loc[:, ['银行结售汇:差额:自身:当月值', '银行结售汇:差额:代客:当月值', '银行结售汇顺差:当月值']]
pro_df.columns = [i.replace(':', '-') for i in pro_df.columns]
st.line_chart(pro_df.dropna().astype(float))
def bank_spot_forex(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, ['银行远期结售汇:差额:当月值', '平均汇率:美元兑人民币']].reset_index()
pro_df['平均汇率:美元兑人民币(逆序)'] = pro_df['平均汇率:美元兑人民币'].pct_change(1) * 100 * (-1)
pro_df.columns = [i.replace(':', '-') for i in pro_df.columns]
bars = alt.Chart(pro_df).mark_bar().encode(
x='指标名称',
y='银行远期结售汇-差额-当月值'
)
line = alt.Chart(pro_df).mark_line(color='red').encode(
x='指标名称',
y='平均汇率-美元兑人民币(逆序)'
)
# 将柱状图和折线图组合在一起
chart = alt.layer(bars, line).resolve_scale(y='independent')
st.altair_chart(chart, use_container_width=True)
def capital_current_account(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
pro_df['经常账户差额'] = pro_df['经常账户:差额:当季值']
pro_df['资本金融账户差额'] = pro_df['资本和金融账户:差额:当季值'] - pro_df['金融账户:储备资产:储备资产:当季值']
pro_df = pro_df.loc[:, ['经常账户差额', '资本金融账户差额']]
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def balance_of_payments(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:,
['经常账户:差额:当季值', '资本和金融账户:差额:当季值', '金融账户:储备资产:储备资产:当季值',
'净误差与遗漏:差额:当季值', '平均汇率:美元兑人民币']].reset_index()
pro_df['经常账户差额'] = pro_df['经常账户:差额:当季值']
pro_df['资本金融账户差额'] = pro_df['资本和金融账户:差额:当季值'] - pro_df['金融账户:储备资产:储备资产:当季值']
pro_df['国际收支差额'] = pro_df['经常账户差额'] + pro_df['资本金融账户差额']
pro_df['平均汇率:美元兑人民币(逆序)'] = pro_df['平均汇率:美元兑人民币'].pct_change(1) * 100 * (-1)
pro_df = pro_df.loc[:, ['指标名称', '国际收支差额', '平均汇率:美元兑人民币(逆序)']].dropna()
print(pro_df)
pro_df.columns = [i.replace(':', '-') for i in pro_df.columns]
bars = alt.Chart(pro_df).mark_bar().encode(
x='指标名称',
y='国际收支差额'
)
line = alt.Chart(pro_df).mark_line(color='red').encode(
x='指标名称',
y='平均汇率-美元兑人民币(逆序)'
)
# 将柱状图和折线图组合在一起
chart = alt.layer(bars, line).resolve_scale(y='independent')
st.altair_chart(chart, use_container_width=True)
def detail_current_account(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
pro_df = pro_df.loc[:,
['经常账户:二次收入:差额:当季值', '经常账户:初次收入:差额:当季值', '经常账户:货物:差额:当季值',
'经常账户:服务:差额:当季值']]
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def detail_capital_account(self):
start_date = '2000-01'
pro_df = self.df.loc[start_date:, :]
pro_df = pro_df.loc[:,
['金融账户:非储备性质的金融账户:证券投资:当季值', '金融账户:非储备性质的金融账户:直接投资:当季值',
'金融账户:非储备性质的金融账户:其他投资:当季值']]
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
class RealEstateInvest:
def __init__(self):
df = preprocess_choice_data('data/房地产投资.xlsx')
df = df[(df['指标名称'] >= '2000-01') & (df['指标名称'] <= '2099-01')]
df = df.replace('--', np.nan)
df = df.set_index('指标名称').sort_index()
self.df = df
def total_plot(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='real_estate_total_plot')
pro_df = self.df.copy()
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[start_date:, ['房地产开发投资完成额:累计值', '房地产开发投资完成额:累计同比']].reset_index()
pro_df.columns = [i.replace(':', '-') for i in pro_df.columns]
bars = alt.Chart(pro_df).mark_bar().encode(
x='指标名称',
y='房地产开发投资完成额-累计值'
)
line = alt.Chart(pro_df).mark_line(color='red').encode(
x='指标名称',
y='房地产开发投资完成额-累计同比'
)
# 将柱状图和折线图组合在一起
chart = alt.layer(bars, line).resolve_scale(y='independent')
st.altair_chart(chart, use_container_width=True)
def season_plot(self):
start_date = '2019-01'
pro_df = self.df.loc[start_date:, ['房地产开发投资完成额:累计同比']]
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df['年份'] = [i[:4] for i in pro_df.index]
pro_df = pro_df.pivot(index=['月份'], columns=['年份'], values='房地产开发投资完成额:累计同比')
st.line_chart(pro_df)
def construction_type(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='construction_type')
pro_df = self.df.copy()
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[start_date:, ['房地产开发投资完成额:住宅:累计值', '房地产开发投资完成额:办公楼:累计值',
'房地产开发投资完成额:商业营业用房:累计值',
'房地产开发投资完成额:其他:累计值']]
pro_df['房地产开发投资完成额:其他:累计值'] = pro_df['房地产开发投资完成额:其他:累计值'] / 1e4
pro_df = pro_df.div(pro_df.sum(axis=1).replace(0, np.nan), axis=0)
pro_df.columns = ['住宅', '办公楼', '商业营业用房', '其他']
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def using_type(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='using_type')
pro_df = self.df.copy()
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[start_date:,
['房地产开发投资完成额:建筑工程:累计值', '房地产开发投资完成额:安装工程:累计值',
'房地产开发投资完成额:设备工器具购置:累计值', '房地产开发投资完成额:其他费用:累计值']]
pro_df = pro_df.div(pro_df.sum(axis=1).replace(0, np.nan), axis=0)
pro_df.columns = ['建筑工程', '安装工程', '设备工器具购置', '其他费用']
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def area_type(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='area_type')
pro_df = self.df.copy()
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[start_date:,
['房地产开发投资完成额:东部地区:累计值', '房地产开发投资完成额:中部地区:累计值',
'房地产开发投资完成额:西部地区:累计值']]
pro_df = pro_df.div(pro_df.sum(axis=1).replace(0, np.nan), axis=0)
pro_df.columns = ['东部地区', '中部地区', '西部地区']
pro_df = pro_df.astype(float)
st.bar_chart(pro_df)
def money_plot(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='money_plot')
pro_df = self.df.copy()
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[start_date:, ['房地产开发投资:本年实际到位资金:合计:累计值',
'房地产开发投资:本年实际到位资金:合计:累计同比']].reset_index()
pro_df.columns = [i.replace(':', '-') for i in pro_df.columns]
bars = alt.Chart(pro_df).mark_bar().encode(
x='指标名称',
y='房地产开发投资:本年实际到位资金:合计:累计值'.replace(':', '-')
)
line = alt.Chart(pro_df).mark_line(color='red').encode(
x='指标名称',
y='房地产开发投资:本年实际到位资金:合计:累计同比'.replace(':', '-')
)
# 将柱状图和折线图组合在一起
chart = alt.layer(bars, line).resolve_scale(y='independent')
st.altair_chart(chart, use_container_width=True)
def money_structure(self):
start_date = '2000-01'
on = st.toggle("仅显示第12月(年末)", key='money_structure')
pro_df = self.df.copy()
if on:
pro_df['月份'] = [i[-2:] for i in pro_df.index]
pro_df = pro_df[pro_df['月份'] == '12']
pro_df = pro_df.loc[start_date:,
['房地产开发企业到位资金:国内贷款:累计值', '房地产开发企业到位资金:利用外资:累计值',