Spaces:
Sleeping
Sleeping
Update dataset_import.py
Browse files- dataset_import.py +13 -4
dataset_import.py
CHANGED
@@ -17,17 +17,26 @@ def load_data():
|
|
17 |
# List available files in the data directory
|
18 |
available_files = [f for f in os.listdir('./data') if f.endswith('.csv')]
|
19 |
|
|
|
|
|
|
|
|
|
20 |
# Ask user to select which file to load
|
21 |
selected_file = st.selectbox('Select a file to load', available_files)
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def main():
|
28 |
st.title("Kaggle Dataset Loader")
|
29 |
data = load_data()
|
30 |
-
|
|
|
31 |
|
32 |
if __name__ == "__main__":
|
33 |
main()
|
|
|
17 |
# List available files in the data directory
|
18 |
available_files = [f for f in os.listdir('./data') if f.endswith('.csv')]
|
19 |
|
20 |
+
if len(available_files) == 0:
|
21 |
+
st.error("No CSV files found in the dataset folder.")
|
22 |
+
return None
|
23 |
+
|
24 |
# Ask user to select which file to load
|
25 |
selected_file = st.selectbox('Select a file to load', available_files)
|
26 |
|
27 |
+
if selected_file:
|
28 |
+
# Load the selected dataset
|
29 |
+
data = pd.read_csv(f'./data/{selected_file}')
|
30 |
+
return data
|
31 |
+
else:
|
32 |
+
st.error("Please select a valid file.")
|
33 |
+
return None
|
34 |
|
35 |
def main():
|
36 |
st.title("Kaggle Dataset Loader")
|
37 |
data = load_data()
|
38 |
+
if data is not None:
|
39 |
+
st.write(data.head())
|
40 |
|
41 |
if __name__ == "__main__":
|
42 |
main()
|