varshitha22 commited on
Commit
d1bd976
·
verified ·
1 Parent(s): 494510f

Update pages/EDA.py

Browse files
Files changed (1) hide show
  1. pages/EDA.py +53 -1
pages/EDA.py CHANGED
@@ -462,4 +462,56 @@ st.markdown("""
462
  2. Requires very little water and nutrients, making it cost-effective.
463
  3. Has a stable market demand
464
  </div>
465
- """, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
462
  2. Requires very little water and nutrients, making it cost-effective.
463
  3. Has a stable market demand
464
  </div>
465
+ """, unsafe_allow_html=True)
466
+
467
+
468
+
469
+
470
+ # **Scatter Plot: Rainfall vs. Crop**
471
+ st.subheader(" Rainfall vs. Crop")
472
+ fig, ax = plt.subplots(figsize=(5, 3)) # Reduced size
473
+ sns.scatterplot(data=df, x="Rainfall", y="Crop", hue="Crop", palette="rainbow", legend=False, ax=ax)
474
+ ax.set_xlabel("Rainfall (mm)", fontsize=8)
475
+ ax.set_ylabel("Crop", fontsize=8)
476
+ ax.set_title("Rainfall vs Crop Type", fontsize=10)
477
+ st.pyplot(fig)
478
+
479
+ # **Scatter Plot: Temperature vs. Humidity**
480
+ st.subheader("Temperature vs. Humidity")
481
+ fig, ax = plt.subplots(figsize=(5, 3)) # Reduced size
482
+ sns.scatterplot(data=df, x="Temperature", y="Humidity", alpha=0.6, color="blue", ax=ax)
483
+ ax.set_xlabel("Temperature (°C)", fontsize=8)
484
+ ax.set_ylabel("Humidity (%)", fontsize=8)
485
+ ax.set_title("Temperature vs Humidity", fontsize=10)
486
+ st.pyplot(fig)
487
+
488
+ # **Heatmap: Correlation Between Soil & Climate Factors**
489
+ st.subheader("Correlation Heatmap of Soil & Climate Factors")
490
+ corr_matrix = df[['Nitrogen', 'Phosphorus', 'Potassium', 'Temperature', 'Humidity', 'pH_Value', 'Rainfall']].corr()
491
+ fig, ax = plt.subplots(figsize=(5, 3)) # Reduced size
492
+ sns.heatmap(corr_matrix, annot=True, cmap="coolwarm", ax=ax)
493
+ ax.set_title("Correlation Heatmap", fontsize=10)
494
+ st.pyplot(fig)
495
+
496
+ # **Crop Recommendations Based on Season**
497
+ st.subheader("🌾 Crop Recommendations by Season")
498
+
499
+ # **Define Seasonal Conditions**
500
+ summer_conditions = (df["Temperature"].between(20, 40)) & (df["Rainfall"].between(50, 200)) & (df["Humidity"].between(40, 70))
501
+ rainy_conditions = (df["Temperature"].between(20, 30)) & (df["Rainfall"] > 200) & (df["Humidity"].between(65, 95))
502
+ winter_conditions = (df["Temperature"].between(10, 20)) & (df["Rainfall"] < 150) & (df["Humidity"].between(30, 70))
503
+
504
+ # **Get Unique Crops for Each Season**
505
+ summer_crops = df[summer_conditions]["Crop"].unique().tolist()
506
+ rainy_crops = df[rainy_conditions]["Crop"].unique().tolist()
507
+ winter_crops = df[winter_conditions]["Crop"].unique().tolist()
508
+
509
+ # **Display Crop Recommendations**
510
+ st.markdown("### ☀ Summer Crops")
511
+ st.write(", ".join(summer_crops) if summer_crops else "No crops suitable for summer.")
512
+
513
+ st.markdown("### 🌧 Rainy Season Crops")
514
+ st.write(", ".join(rainy_crops) if rainy_crops else "No crops suitable for the rainy season.")
515
+
516
+ st.markdown("### ❄ Winter Crops")
517
+ st.write(", ".join(winter_crops) if winter_crops else "No crops suitable for winter.")