Abu1998 commited on
Commit
239b4ff
·
verified ·
1 Parent(s): 29a56ed

Update dataset_import.py

Browse files
Files changed (1) hide show
  1. dataset_import.py +12 -12
dataset_import.py CHANGED
@@ -8,7 +8,7 @@ def download_dataset():
8
  os.makedirs('./data')
9
 
10
  # Download the dataset using Kaggle API
11
- os.system("kaggle datasets download -d mohaideenabuthahir/analyzeyt")
12
 
13
  def load_data():
14
  # Ensure dataset is downloaded
@@ -17,17 +17,17 @@ 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
- # Load the selected dataset
24
- data = pd.read_csv(f'./data/{selected_file}')
25
- return data
26
-
27
- def main():
28
- st.title("Kaggle Dataset Loader")
29
- data = load_data()
30
- st.write(data.head())
31
-
32
- if __name__ == "__main__":
33
- main()
 
8
  os.makedirs('./data')
9
 
10
  # Download the dataset using Kaggle API
11
+ os.system("kaggle datasets download -d mohaideenabuthahir/analyzeyt -p ./data --unzip")
12
 
13
  def load_data():
14
  # Ensure dataset is downloaded
 
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