Update app.py
Browse files
app.py
CHANGED
|
@@ -94,22 +94,17 @@ def get_statistical_metadata(data_name, start=1, end=10):
|
|
| 94 |
def display_data_as_table(data):
|
| 95 |
if data:
|
| 96 |
if isinstance(data, dict):
|
| 97 |
-
if "StatisticItemList"
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
df = pd.DataFrame(data["StatisticWordList"]["row"])
|
| 103 |
-
elif "KeyStatisticList" in data:
|
| 104 |
-
df = pd.DataFrame(data["KeyStatisticList"]["row"])
|
| 105 |
-
elif "StatisticMeta" in data:
|
| 106 |
-
df = pd.DataFrame(data["StatisticMeta"]["row"])
|
| 107 |
else:
|
| 108 |
st.write("데이터를 표시할 수 없습니다.")
|
| 109 |
-
return
|
| 110 |
-
st.dataframe(df)
|
| 111 |
else:
|
| 112 |
st.write("데이터 형식이 잘못되었습니다.")
|
|
|
|
|
|
|
| 113 |
|
| 114 |
# Streamlit 앱 구성
|
| 115 |
st.title("한국은행 ECOS API 데이터 조회")
|
|
@@ -121,38 +116,47 @@ option = st.sidebar.selectbox(
|
|
| 121 |
("서비스 통계 목록", "통계용어사전", "통계 세부항목 목록", "통계 조회 조건 설정", "100대 통계지표", "통계 메타DB")
|
| 122 |
)
|
| 123 |
|
| 124 |
-
#
|
| 125 |
if option == "서비스 통계 목록":
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
| 128 |
|
| 129 |
elif option == "통계용어사전":
|
| 130 |
-
term = st.text_input("용어 입력:"
|
| 131 |
-
if
|
| 132 |
-
|
| 133 |
-
|
|
|
|
| 134 |
|
| 135 |
elif option == "통계 세부항목 목록":
|
| 136 |
-
stat_code = st.text_input("
|
| 137 |
-
if
|
| 138 |
-
|
| 139 |
-
|
|
|
|
| 140 |
|
| 141 |
elif option == "통계 조회 조건 설정":
|
| 142 |
-
stat_code = st.text_input("
|
| 143 |
-
period = st.text_input("주기 입력 (예: A, Q, M):"
|
| 144 |
-
start_date = st.text_input("검색 시작일자 입력 (예: 2015, 2015Q1, 201501, 20150101):"
|
| 145 |
-
end_date = st.text_input("검색 종료일자 입력 (예: 2021, 2021Q1, 202101, 20210101):"
|
| 146 |
-
if
|
| 147 |
-
|
| 148 |
-
|
|
|
|
| 149 |
|
| 150 |
elif option == "100대 통계지표":
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
elif option == "통계 메타DB":
|
| 155 |
-
data_name = st.text_input("데이터명 입력:"
|
| 156 |
-
if
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
| 94 |
def display_data_as_table(data):
|
| 95 |
if data:
|
| 96 |
if isinstance(data, dict):
|
| 97 |
+
if any(key in data for key in ["StatisticItemList", "StatisticTableList", "StatisticWordList", "KeyStatisticList", "StatisticMeta"]):
|
| 98 |
+
for key in data:
|
| 99 |
+
if key in ["StatisticItemList", "StatisticTableList", "StatisticWordList", "KeyStatisticList", "StatisticMeta"]:
|
| 100 |
+
df = pd.DataFrame(data[key]["row"])
|
| 101 |
+
st.dataframe(df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
else:
|
| 103 |
st.write("데이터를 표시할 수 없습니다.")
|
|
|
|
|
|
|
| 104 |
else:
|
| 105 |
st.write("데이터 형식이 잘못되었습니다.")
|
| 106 |
+
else:
|
| 107 |
+
st.write("데이터를 로드할 수 없습니다.")
|
| 108 |
|
| 109 |
# Streamlit 앱 구성
|
| 110 |
st.title("한국은행 ECOS API 데이터 조회")
|
|
|
|
| 116 |
("서비스 통계 목록", "통계용어사전", "통계 세부항목 목록", "통계 조회 조건 설정", "100대 통계지표", "통계 메타DB")
|
| 117 |
)
|
| 118 |
|
| 119 |
+
# 입력 양식 구성
|
| 120 |
if option == "서비스 통계 목록":
|
| 121 |
+
stat_code = st.text_input("통계표코드 입력 (선택사항):")
|
| 122 |
+
if st.button("실행"):
|
| 123 |
+
data = get_service_statistics(stat_code=stat_code)
|
| 124 |
+
display_data_as_table(data)
|
| 125 |
|
| 126 |
elif option == "통계용어사전":
|
| 127 |
+
term = st.text_input("용어 입력:")
|
| 128 |
+
if st.button("실행"):
|
| 129 |
+
if term:
|
| 130 |
+
data = get_statistical_glossary(term)
|
| 131 |
+
display_data_as_table(data)
|
| 132 |
|
| 133 |
elif option == "통계 세부항목 목록":
|
| 134 |
+
stat_code = st.text_input("통계표코드 입력:")
|
| 135 |
+
if st.button("실행"):
|
| 136 |
+
if stat_code:
|
| 137 |
+
data = get_statistic_detail_items(stat_code)
|
| 138 |
+
display_data_as_table(data)
|
| 139 |
|
| 140 |
elif option == "통계 조회 조건 설정":
|
| 141 |
+
stat_code = st.text_input("통계표코드 입력:")
|
| 142 |
+
period = st.text_input("주기 입력 (예: A, Q, M):")
|
| 143 |
+
start_date = st.text_input("검색 시작일자 입력 (예: 2015, 2015Q1, 201501, 20150101):")
|
| 144 |
+
end_date = st.text_input("검색 종료일자 입력 (예: 2021, 2021Q1, 202101, 20210101):")
|
| 145 |
+
if st.button("실행"):
|
| 146 |
+
if stat_code and period and start_date and end_date:
|
| 147 |
+
data = get_statistic_search_conditions(stat_code, period, start_date, end_date)
|
| 148 |
+
display_data_as_table(data)
|
| 149 |
|
| 150 |
elif option == "100대 통계지표":
|
| 151 |
+
start = st.text_input("요청 시작 건수 (예: 1):", "1")
|
| 152 |
+
end = st.text_input("요청 종료 건수 (예: 10):", "10")
|
| 153 |
+
if st.button("실행"):
|
| 154 |
+
data = get_top_100_statistics(start=start, end=end)
|
| 155 |
+
display_data_as_table(data)
|
| 156 |
|
| 157 |
elif option == "통계 메타DB":
|
| 158 |
+
data_name = st.text_input("데이터명 입력:")
|
| 159 |
+
if st.button("실행"):
|
| 160 |
+
if data_name:
|
| 161 |
+
data = get_statistical_metadata(data_name)
|
| 162 |
+
display_data_as_table(data)
|