MarkusHenriksson13 commited on
Commit
4c6217f
·
verified ·
1 Parent(s): 36201c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
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
- # 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
 
 
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