MarkusHenriksson13 commited on
Commit
65d7d0a
·
verified ·
1 Parent(s): 4ec5b89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -25
app.py CHANGED
@@ -7,31 +7,33 @@ import matplotlib.pyplot as plt
7
  import altair as alt
8
 
9
 
10
- # Defining filepath locally
11
- file_path = '/Users/markushenriksson/Desktop/Data/Python/Projects/ds-master/data/assignments_datasets/KIVA'
12
-
13
- # Changing to the correct file and changing to the the working directory
14
- os.chdir(file_path)
15
-
16
- # Loading datasets
17
- try: #Try function to do specific command with exceptions
18
- # Different parts of the dataset
19
- df_part_0 = pd.read_csv('kiva_loans_part_0.csv')
20
- df_part_1 = pd.read_csv('kiva_loans_part_1.csv')
21
- df_part_2 = pd.read_csv('kiva_loans_part_2.csv')
22
-
23
- # Concatonating the subdatasets
24
- df_combined = pd.concat([df_part_0, df_part_1, df_part_2], ignore_index=True)
25
-
26
- # Displaying dataset header
27
- st.title("KIVA Loans Dataset Visualization")
28
- st.write("### Data Preview")
29
- st.dataframe(df_combined.head())
30
-
31
- except FileNotFoundError as e:
32
- st.error(f"File not found: {e}")
33
- except Exception as e:
34
- st.error(f"An error occurred: {e}")
 
 
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