Roberta2024 commited on
Commit
7fe36db
·
verified ·
1 Parent(s): 3a5a6b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -15,7 +15,8 @@ with open("TaipeiSansTCBeta-Regular.ttf", "wb") as font_file:
15
  @st.cache_data
16
  def download_csv(url):
17
  response = requests.get(url)
18
- df = pd.read_csv(StringIO(response.text))
 
19
  df = df.fillna(0) # Fill missing values with 0
20
  return df
21
 
@@ -39,7 +40,7 @@ st.markdown("""
39
  }
40
  </style>
41
  """, unsafe_allow_html=True)
42
- st.markdown('<p class="big-font">ESG Data Visualization</p>', unsafe_allow_html=True)
43
 
44
  # Sidebar for data selection and chart options
45
  st.sidebar.header("設置")
@@ -56,7 +57,7 @@ if st.sidebar.button("載入資料"):
56
 
57
  df = download_csv(urls[selected_option])
58
 
59
- # Displaying the DataFrame without styling
60
  st.header(f"{selected_option} 資料")
61
  st.dataframe(df)
62
 
@@ -93,7 +94,7 @@ if st.sidebar.button("載入資料"):
93
  st.warning("沒有足夠的數值型欄位來創建圖表。請選擇另一個數據集。")
94
 
95
  # Add download button for the data
96
- csv = df.to_csv(index=False)
97
  st.download_button(
98
  label="下載資料為 CSV",
99
  data=csv,
@@ -103,4 +104,4 @@ if st.sidebar.button("載入資料"):
103
 
104
  # Footer
105
  st.markdown("---")
106
- st.markdown("Created with ❤️ using Streamlit")
 
15
  @st.cache_data
16
  def download_csv(url):
17
  response = requests.get(url)
18
+ response.encoding = 'utf-8' # Set the encoding to UTF-8
19
+ df = pd.read_csv(StringIO(response.text), encoding='utf-8')
20
  df = df.fillna(0) # Fill missing values with 0
21
  return df
22
 
 
40
  }
41
  </style>
42
  """, unsafe_allow_html=True)
43
+ st.markdown('<p class="big-font">ESG 數據視覺化</p>', unsafe_allow_html=True)
44
 
45
  # Sidebar for data selection and chart options
46
  st.sidebar.header("設置")
 
57
 
58
  df = download_csv(urls[selected_option])
59
 
60
+ # Displaying the DataFrame
61
  st.header(f"{selected_option} 資料")
62
  st.dataframe(df)
63
 
 
94
  st.warning("沒有足夠的數值型欄位來創建圖表。請選擇另一個數據集。")
95
 
96
  # Add download button for the data
97
+ csv = df.to_csv(index=False, encoding='utf-8-sig') # Use UTF-8 with BOM for Excel compatibility
98
  st.download_button(
99
  label="下載資料為 CSV",
100
  data=csv,
 
104
 
105
  # Footer
106
  st.markdown("---")
107
+ st.markdown("使用 Streamlit 創建 ❤️")