trohith89 commited on
Commit
8984d08
·
verified ·
1 Parent(s): dc44ae9

Update pages/2_Data_CLeaning_and_Preprocessing.py

Browse files
pages/2_Data_CLeaning_and_Preprocessing.py CHANGED
@@ -102,10 +102,25 @@ if uploaded_file is not None:
102
  file_name="cleaned_dataset.csv",
103
  mime="text/csv"
104
  )
 
 
 
 
 
 
105
  data = data.rename(columns={'ProductCategory': 'Category', 'ProductBrand': 'Brand', 'ProductPrice': 'Price'})
106
- # Correct Price Column values (round off to 2 decimal places)
107
- data['Price'] = data['Price'].apply(lambda x: round(x,2))
108
- print(data.head())
 
 
 
 
 
 
 
 
 
109
  except pd.errors.EmptyDataError:
110
  st.error("The uploaded CSV file is empty. Please upload a valid file.")
111
  except pd.errors.ParserError:
 
102
  file_name="cleaned_dataset.csv",
103
  mime="text/csv"
104
  )
105
+ # Check the columns before renaming
106
+ st.write("### Dataset Columns:")
107
+ st.write(data.columns)
108
+
109
+ # Renaming columns if they exist
110
+ if 'ProductCategory' in data.columns and 'ProductBrand' in data.columns and 'ProductPrice' in data.columns:
111
  data = data.rename(columns={'ProductCategory': 'Category', 'ProductBrand': 'Brand', 'ProductPrice': 'Price'})
112
+ st.success("Columns renamed successfully!")
113
+ else:
114
+ st.warning("Columns 'ProductCategory', 'ProductBrand', or 'ProductPrice' not found in the dataset.")
115
+
116
+ # Now check if 'Category' exists and plot
117
+ if 'Category' in data.columns:
118
+ st.write("### Bar Plot for Category")
119
+ fig, ax = plt.subplots()
120
+ sns.countplot(x='Category', data=data, palette='viridis', ax=ax)
121
+ st.pyplot(fig)
122
+ else:
123
+ st.warning("'Category' column not found for plotting.")
124
  except pd.errors.EmptyDataError:
125
  st.error("The uploaded CSV file is empty. Please upload a valid file.")
126
  except pd.errors.ParserError: