Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,31 +7,33 @@ import matplotlib.pyplot as plt
|
|
| 7 |
import altair as alt
|
| 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 |
# Introduction
|
| 37 |
|
|
|
|
| 7 |
import altair as alt
|
| 8 |
|
| 9 |
|
| 10 |
+
# Define the path to your data files relative to the script's location
|
| 11 |
+
base_path = os.path.dirname(__file__)
|
| 12 |
+
data_folder = os.path.join(base_path, 'data', 'assignments_datasets', 'KIVA')
|
| 13 |
+
|
| 14 |
+
# Load and concatenate datasets
|
| 15 |
+
def load_data():
|
| 16 |
+
try:
|
| 17 |
+
# Construct full paths to the data files and load each part of the dataset
|
| 18 |
+
df_part_0 = pd.read_csv(os.path.join(data_folder, 'kiva_loans_part_0.csv'))
|
| 19 |
+
df_part_1 = pd.read_csv(os.path.join(data_folder, 'kiva_loans_part_1.csv'))
|
| 20 |
+
df_part_2 = pd.read_csv(os.path.join(data_folder, 'kiva_loans_part_2.csv'))
|
| 21 |
+
|
| 22 |
+
# Concatenate the subdatasets
|
| 23 |
+
df_combined = pd.concat([df_part_0, df_part_1, df_part_2], ignore_index=True)
|
| 24 |
+
|
| 25 |
+
# Display the dataset header in Streamlit
|
| 26 |
+
st.title("KIVA Loans Dataset Visualization")
|
| 27 |
+
st.write("### Data Preview")
|
| 28 |
+
st.dataframe(df_combined.head())
|
| 29 |
+
|
| 30 |
+
except FileNotFoundError as e:
|
| 31 |
+
st.error(f"File not found: {e}")
|
| 32 |
+
except Exception as e:
|
| 33 |
+
st.error(f"An error occurred: {e}")
|
| 34 |
+
|
| 35 |
+
# Call the function to load and display data
|
| 36 |
+
load_data()
|
| 37 |
|
| 38 |
# Introduction
|
| 39 |
|