Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,19 +7,18 @@ import matplotlib.pyplot as plt
|
|
| 7 |
import altair as alt
|
| 8 |
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# Function to load and display data
|
| 15 |
def load_data():
|
| 16 |
try:
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
os.path.join(data_folder, f'kiva_loans_part_{i}.csv') for i in range(3)
|
| 20 |
-
]
|
| 21 |
-
# Load data parts
|
| 22 |
-
data_parts = [pd.read_csv(path) for path in file_paths]
|
| 23 |
|
| 24 |
# Concatenate the datasets
|
| 25 |
df_combined = pd.concat(data_parts, ignore_index=True)
|
|
@@ -31,14 +30,20 @@ def load_data():
|
|
| 31 |
|
| 32 |
return df_combined
|
| 33 |
|
| 34 |
-
except FileNotFoundError as e:
|
| 35 |
-
st.error(f"File not found: {e}")
|
| 36 |
except Exception as e:
|
| 37 |
st.error(f"An error occurred: {e}")
|
|
|
|
| 38 |
|
| 39 |
# Load and display data
|
| 40 |
df_combined = load_data()
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
# Introduction
|
| 43 |
|
| 44 |
# KIVA Loans Distribution Dashboard
|
|
|
|
| 7 |
import altair as alt
|
| 8 |
|
| 9 |
|
| 10 |
+
# URLs to your data files hosted on Hugging Face
|
| 11 |
+
file_urls = [
|
| 12 |
+
'https://huggingface.co/spaces/MarkusHenriksson13/Assignment_2/resolve/main/data/assignments_datasets/KIVA/kiva_loans_part_0.csv',
|
| 13 |
+
'https://huggingface.co/spaces/MarkusHenriksson13/Assignment_2/resolve/main/data/assignments_datasets/KIVA/kiva_loans_part_1.csv',
|
| 14 |
+
'https://huggingface.co/spaces/MarkusHenriksson13/Assignment_2/resolve/main/data/assignments_datasets/KIVA/kiva_loans_part_2.csv'
|
| 15 |
+
]
|
| 16 |
|
| 17 |
# Function to load and display data
|
| 18 |
def load_data():
|
| 19 |
try:
|
| 20 |
+
# Load data parts from URLs
|
| 21 |
+
data_parts = [pd.read_csv(url) for url in file_urls]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Concatenate the datasets
|
| 24 |
df_combined = pd.concat(data_parts, ignore_index=True)
|
|
|
|
| 30 |
|
| 31 |
return df_combined
|
| 32 |
|
|
|
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
st.error(f"An error occurred: {e}")
|
| 35 |
+
return None
|
| 36 |
|
| 37 |
# Load and display data
|
| 38 |
df_combined = load_data()
|
| 39 |
|
| 40 |
+
# Ensure df_combined is properly loaded before using it
|
| 41 |
+
if df_combined is not None:
|
| 42 |
+
sectors = df_combined['sector'].unique().tolist()
|
| 43 |
+
st.write("Unique sectors:", sectors)
|
| 44 |
+
else:
|
| 45 |
+
st.warning("Data could not be loaded; please check the file paths and try again.")
|
| 46 |
+
|
| 47 |
# Introduction
|
| 48 |
|
| 49 |
# KIVA Loans Distribution Dashboard
|