Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,32 +8,36 @@ 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 |
-
#
|
| 15 |
def load_data():
|
| 16 |
try:
|
| 17 |
-
# Construct full paths to the data files
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
# Concatenate the
|
| 23 |
-
df_combined = pd.concat(
|
| 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 |
-
#
|
| 36 |
-
load_data()
|
| 37 |
|
| 38 |
# Introduction
|
| 39 |
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
# Define the path to your data files relative to the script's location
|
| 11 |
+
base_path = os.path.dirname(__file__) # Get the directory of the current script
|
| 12 |
data_folder = os.path.join(base_path, 'data', 'assignments_datasets', 'KIVA')
|
| 13 |
|
| 14 |
+
# Function to load and display data
|
| 15 |
def load_data():
|
| 16 |
try:
|
| 17 |
+
# Construct full paths to the data files
|
| 18 |
+
file_paths = [
|
| 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)
|
| 26 |
|
| 27 |
# Display the dataset header in Streamlit
|
| 28 |
st.title("KIVA Loans Dataset Visualization")
|
| 29 |
st.write("### Data Preview")
|
| 30 |
st.dataframe(df_combined.head())
|
| 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 |
|