Spaces:
Sleeping
Sleeping
Update pages/EDA.py
Browse files- pages/EDA.py +27 -25
pages/EDA.py
CHANGED
|
@@ -131,21 +131,6 @@ feature_mapping = {
|
|
| 131 |
}
|
| 132 |
viz_option = st.selectbox("Select a feature visualization:", options=list(feature_mapping.keys()))
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
# Feature Visualization
|
| 138 |
-
feature_mapping = {
|
| 139 |
-
"Nitrogen Requirement per Crop": "Nitrogen",
|
| 140 |
-
"Phosphorus Requirement per Crop": "Phosphorus",
|
| 141 |
-
"Potassium Requirement per Crop": "Potassium",
|
| 142 |
-
"Temperature Distribution": "Temperature",
|
| 143 |
-
"Humidity Distribution": "Humidity",
|
| 144 |
-
"pH Value Distribution": "pH_Value",
|
| 145 |
-
"Rainfall Distribution": "Rainfall",
|
| 146 |
-
}
|
| 147 |
-
viz_option = st.select_slider("Select a feature visualization:", options=list(feature_mapping.keys()))
|
| 148 |
-
|
| 149 |
# Function to plot feature distribution
|
| 150 |
def plot_feature(feature, title):
|
| 151 |
fig, ax = plt.subplots(figsize=(6, 3)) # Reduced plot size
|
|
@@ -158,6 +143,19 @@ def plot_feature(feature, title):
|
|
| 158 |
# Display selected feature plot
|
| 159 |
plot_feature(feature_mapping[viz_option], viz_option)
|
| 160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
# Pie Chart for Crop Proportions (Displayed Separately)
|
| 162 |
st.subheader("📊 Crop Proportions")
|
| 163 |
crop_counts = df['Crop'].value_counts()
|
|
@@ -177,7 +175,10 @@ st.markdown(
|
|
| 177 |
"<p style='color:green; font-size:16px;'>✔ Crops that require above-average soil nutrients & climate factors: Banana, Rice, Papaya, Jute.</p>",
|
| 178 |
unsafe_allow_html=True
|
| 179 |
)
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
# Slider for Soil Nutrient-Based Crop Insights
|
| 183 |
st.subheader("🌿 Soil Nutrient-Based Crop Insights")
|
|
@@ -206,28 +207,29 @@ if viz_option == "Crops in Nutrient-Rich Soil":
|
|
| 206 |
(df['Phosphorus'] >= avg_phosphorus) &
|
| 207 |
(df['Potassium'] >= avg_potassium)
|
| 208 |
]['Crop']
|
|
|
|
| 209 |
plot_nutrient_crops(more_avg_of_soil_nutrients, "Crops Growing in Nutrient-Rich Soil")
|
|
|
|
| 210 |
st.markdown(
|
| 211 |
-
"<p style='color:green; font-size:18px;'>1.
|
| 212 |
unsafe_allow_html=True
|
| 213 |
)
|
| 214 |
st.markdown(
|
| 215 |
-
"<p style='color:green; font-size:18px;'>2.
|
| 216 |
unsafe_allow_html=True
|
| 217 |
)
|
| 218 |
-
|
| 219 |
-
"<p style='color:blue; font-size:16px;'>✔ Crops that require below-average soil nutrients & climate factors: Orange, Mango, Coconut.</p>",
|
| 220 |
-
unsafe_allow_html=True
|
| 221 |
-
)
|
| 222 |
elif viz_option == "Crops in Nutrient-Poor Soil":
|
| 223 |
less_avg_of_soil_nutrients = df[
|
| 224 |
(df['Nitrogen'] < avg_nitrogen) &
|
| 225 |
(df['Phosphorus'] < avg_phosphorus) &
|
| 226 |
(df['Potassium'] < avg_potassium)
|
| 227 |
]['Crop']
|
|
|
|
| 228 |
plot_nutrient_crops(less_avg_of_soil_nutrients, "Crops Growing in Nutrient-Poor Soil")
|
|
|
|
| 229 |
# Additional Insights Section
|
| 230 |
-
st.markdown("<h2 style='color: #2E86C1; font-size: 23px;'> Insights
|
| 231 |
st.markdown("""
|
| 232 |
<style>
|
| 233 |
.insights-box {
|
|
@@ -240,7 +242,7 @@ st.markdown("""
|
|
| 240 |
}
|
| 241 |
</style>
|
| 242 |
<div class='insights-box'>
|
| 243 |
-
1.
|
| 244 |
-
2.
|
| 245 |
</div>
|
| 246 |
""", unsafe_allow_html=True)
|
|
|
|
| 131 |
}
|
| 132 |
viz_option = st.selectbox("Select a feature visualization:", options=list(feature_mapping.keys()))
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
# Function to plot feature distribution
|
| 135 |
def plot_feature(feature, title):
|
| 136 |
fig, ax = plt.subplots(figsize=(6, 3)) # Reduced plot size
|
|
|
|
| 143 |
# Display selected feature plot
|
| 144 |
plot_feature(feature_mapping[viz_option], viz_option)
|
| 145 |
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
import streamlit as st
|
| 152 |
+
import pandas as pd
|
| 153 |
+
import seaborn as sns
|
| 154 |
+
import matplotlib.pyplot as plt
|
| 155 |
+
|
| 156 |
+
# Load the dataset
|
| 157 |
+
df = pd.read_csv("your_dataset.csv") # Replace with your actual dataset path
|
| 158 |
+
|
| 159 |
# Pie Chart for Crop Proportions (Displayed Separately)
|
| 160 |
st.subheader("📊 Crop Proportions")
|
| 161 |
crop_counts = df['Crop'].value_counts()
|
|
|
|
| 175 |
"<p style='color:green; font-size:16px;'>✔ Crops that require above-average soil nutrients & climate factors: Banana, Rice, Papaya, Jute.</p>",
|
| 176 |
unsafe_allow_html=True
|
| 177 |
)
|
| 178 |
+
st.markdown(
|
| 179 |
+
"<p style='color:blue; font-size:16px;'>✔ Crops that require below-average soil nutrients & climate factors: Orange, Mango, Coconut.</p>",
|
| 180 |
+
unsafe_allow_html=True
|
| 181 |
+
)
|
| 182 |
|
| 183 |
# Slider for Soil Nutrient-Based Crop Insights
|
| 184 |
st.subheader("🌿 Soil Nutrient-Based Crop Insights")
|
|
|
|
| 207 |
(df['Phosphorus'] >= avg_phosphorus) &
|
| 208 |
(df['Potassium'] >= avg_potassium)
|
| 209 |
]['Crop']
|
| 210 |
+
|
| 211 |
plot_nutrient_crops(more_avg_of_soil_nutrients, "Crops Growing in Nutrient-Rich Soil")
|
| 212 |
+
|
| 213 |
st.markdown(
|
| 214 |
+
"<p style='color:green; font-size:18px;'>1. Banana is the most frequent crop, indicating it requires high soil nutrients.</p>",
|
| 215 |
unsafe_allow_html=True
|
| 216 |
)
|
| 217 |
st.markdown(
|
| 218 |
+
"<p style='color:green; font-size:18px;'>2. Rice, Papaya, and Jute also need good nutrients but less than Banana.</p>",
|
| 219 |
unsafe_allow_html=True
|
| 220 |
)
|
| 221 |
+
|
|
|
|
|
|
|
|
|
|
| 222 |
elif viz_option == "Crops in Nutrient-Poor Soil":
|
| 223 |
less_avg_of_soil_nutrients = df[
|
| 224 |
(df['Nitrogen'] < avg_nitrogen) &
|
| 225 |
(df['Phosphorus'] < avg_phosphorus) &
|
| 226 |
(df['Potassium'] < avg_potassium)
|
| 227 |
]['Crop']
|
| 228 |
+
|
| 229 |
plot_nutrient_crops(less_avg_of_soil_nutrients, "Crops Growing in Nutrient-Poor Soil")
|
| 230 |
+
|
| 231 |
# Additional Insights Section
|
| 232 |
+
st.markdown("<h2 style='color: #2E86C1; font-size: 23px;'> Insights:</h2>", unsafe_allow_html=True)
|
| 233 |
st.markdown("""
|
| 234 |
<style>
|
| 235 |
.insights-box {
|
|
|
|
| 242 |
}
|
| 243 |
</style>
|
| 244 |
<div class='insights-box'>
|
| 245 |
+
1. Orange, Mango, and Coconut are the most frequent crops found in nutrient-poor soil.<br>
|
| 246 |
+
2. These crops are well-adapted to low-fertility conditions and can grow even when nutrient levels are below average.
|
| 247 |
</div>
|
| 248 |
""", unsafe_allow_html=True)
|