<jupyter_start><jupyter_text>Importing the Libraries<jupyter_code>#Importing IMP libs
import numpy as np
import pandas as pd

import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use('fivethirtyeight')

import ipywidgets
from ipywidgets import interact
#Reading dataset
data=pd.read_csv("data.csv")
data.head()
#Checking if there are null vules
data.isnull().sum()

#Total crops that are present
data['label'].value_counts()<jupyter_output><empty_output><jupyter_text>Descriptive Statistics<jupyter_code>#Checking the average values of data
print("Average ratio of nitogen in soil: {0:.2f}".format(data['N'].mean()))
print("Average ratio of phosphoruos in soil: {0:.2f}".format(data['P'].mean()))
print("Average ratio of potassium in soil: {0:.2f}".format(data['K'].mean()))
print("Average temperature in celsius : {0:.2f}".format(data['temperature'].mean()))
print("Average relative humidity in % : {0:.2f}".format(data['humidity'].mean()))
print("Average pH value of soil : {0:.2f}".format(data['ph'].mean()))
print("Average rainfall in the region in mm : {0:.2f}".format(data['rainfall'].mean()))
# Summary of statistics for individual crops
@interact
def statSummary(crops=list(data['label'].value_counts().index)):
    x = data[data['label'] == crops]
    print("----------Stats for Nitrgoen----------")
    print("Min Nitrogen required :", x['N'].min())
    print("Avg Nitrogen required :", x['N'].mean())
    print("Max Nitrogen required :", x['N'].max())
    print("\n")

    print("----------Stats for Phosphorous----------")
    print("Min Phosphorous required :", x['P'].min())
    print("Avg Phosphorous required :", x['P'].mean())
    print("Max Phosphorous required :", x['P'].max())
    print("\n")

    print("----------Stats for Potassium----------")
    print("Min Potassium required :", x['K'].min())
    print("Avg Potassium required :", x['K'].mean())
    print("Max Potassium required :", x['K'].max())
    print("\n")

    print("----------Stats for Temp----------")
    print("Min Temp required :", x['temperature'].min())
    print("Avg Temp required :", x['temperature'].mean())
    print("Max Temp required :", x['temperature'].max())
    print("\n")

    print("----------Stats for Humidity----------")
    print("Min Humidity required :", x['humidity'].min())
    print("Avg Humidity required :", x['humidity'].mean())
    print("Max Humidity required :", x['humidity'].max())
    print("\n")

    print("----------Stats for pH----------")
    print("Min pH required :", x['ph'].min())
    print("Avg pH required :", x['ph'].mean())
    print("Max pH required :", x['ph'].max())
    print("\n")

    print("----------Stats for Rainfall----------")
    print("Min Rainfall required :", x['rainfall'].min())
    print("Avg Rainfall required :", x['rainfall'].mean())
    print("Max Rainfall required :", x['rainfall'].max())
    print("\n")
#Comparing Avg requirement with average conditons 
@interact
def compare(conditions=['N','P','K','temperature','ph','humidity','rainfall']):
    print("Avg Value for", conditions,"is {0:.2f}".format(data[conditions].mean()))
    print("\n")    
    print("Rice : {0:.2f}".format(data[(data['label'] == 'rice')][conditions].mean()))
    print("Black Grams : {0:.2f}".format(data[data['label'] == 'blackgram'][conditions].mean()))
    print("Banana : {0:.2f}".format(data[(data['label'] == 'banana')][conditions].mean()))
    print("Jute : {0:.2f}".format(data[data['label'] == 'jute'][conditions].mean()))
    print("Coconut : {0:.2f}".format(data[(data['label'] == 'coconut')][conditions].mean()))
    print("Apple : {0:.2f}".format(data[data['label'] == 'apple'][conditions].mean()))
    print("Papaya : {0:.2f}".format(data[(data['label'] == 'papaya')][conditions].mean()))
    print("Muskmelon : {0:.2f}".format(data[data['label'] == 'muskmelon'][conditions].mean()))
    print("Grapes : {0:.2f}".format(data[(data['label'] == 'grapes')][conditions].mean()))
    print("Watermelon : {0:.2f}".format(data[data['label'] == 'watermelon'][conditions].mean()))
    print("Kidney Beans: {0:.2f}".format(data[(data['label'] == 'kidneybeans')][conditions].mean()))
    print("Mung Beans : {0:.2f}".format(data[data['label'] == 'mungbean'][conditions].mean()))
    print("Oranges : {0:.2f}".format(data[(data['label'] == 'orange')][conditions].mean()))
    print("Chick Peas : {0:.2f}".format(data[data['label'] == 'chickpea'][conditions].mean()))
    print("Lentils : {0:.2f}".format(data[(data['label'] == 'lentil')][conditions].mean()))
    print("Cotton : {0:.2f}".format(data[data['label'] == 'cotton'][conditions].mean()))
    print("Maize : {0:.2f}".format(data[(data['label'] == 'maize')][conditions].mean()))
    print("Moth Beans : {0:.2f}".format(data[data['label'] == 'mothbeans'][conditions].mean()))
    print("Pigeon Peas : {0:.2f}".format(data[(data['label'] == 'pigeonpeas')][conditions].mean()))
    print("Mango : {0:.2f}".format(data[data['label'] == 'mango'][conditions].mean()))
    print("Pomegranate : {0:.2f}".format(data[(data['label'] == 'pomegranate')][conditions].mean()))
    print("Coffee : {0:.2f}".format(data[data['label'] == 'coffee'][conditions].mean()))
# Made a more optimized function

@interact
def compare(conditions = ['N','P','K','temperature','ph','humidity','rainfall']):
    print("Crops which require greater than average", conditions,'\n')
    print(data[data[conditions] > data[conditions].mean()]['label'].unique())
    print("----------------------------------------------")
    print("Crops which require less than average", conditions,'\n')
    print(data[data[conditions] <= data[conditions].mean()]['label'].unique())<jupyter_output><empty_output><jupyter_text>Analyzing Agricultural Conditions<jupyter_code>#Distribution of Agricultural Conditions

plt.rcParams['figure.figsize'] = (15, 7)

plt.subplot(2, 4, 1)
sns.distplot(data['N'], color = 'lightgrey')
plt.xlabel('Ratio of Nitrogen', fontsize = 12)
plt.grid()

plt.subplot(2, 4, 2)
sns.distplot(data['P'], color = 'skyblue')
plt.xlabel('Ratio of Phosphorous', fontsize = 12)
plt.grid()

plt.subplot(2, 4, 3)
sns.distplot(data['K'], color ='darkblue')
plt.xlabel('Ratio of Potassium', fontsize = 12)
plt.grid()

plt.subplot(2, 4, 4)
sns.distplot(data['temperature'], color = 'black')
plt.xlabel('Temperature', fontsize = 12)
plt.grid()

plt.subplot(2, 4, 5)
sns.distplot(data['rainfall'], color = 'grey')
plt.xlabel('Rainfall', fontsize = 12)
plt.grid()

plt.subplot(2, 4, 6)
sns.distplot(data['humidity'], color = 'lightgreen')
plt.xlabel('Humidity', fontsize = 12)
plt.grid()

plt.subplot(2, 4, 7)
sns.distplot(data['ph'], color = 'darkgreen')
plt.xlabel('pH Level', fontsize = 12)
plt.grid()

plt.suptitle('Distribution for Agricultural Conditions', fontsize = 20)
plt.show()

print("Crops which requires very High Ratio of Nitrogen Content in Soil:", data[data['N'] > 120]['label'].unique())
print("Crops which requires very High Ratio of Phosphorous Content in Soil:", data[data['P'] > 100]['label'].unique())
print("Crops which requires very High Ratio of Potassium Content in Soil:", data[data['K'] > 200]['label'].unique())
print("Crops which requires very High Rainfall:", data[data['rainfall'] > 200]['label'].unique())
print("Crops which requires very Low Temperature :", data[data['temperature'] < 10]['label'].unique())
print("Crops which requires very High Temperature :", data[data['temperature'] > 40]['label'].unique())
print("Crops which requires very Low Humidity:", data[data['humidity'] < 20]['label'].unique())
print("Crops which requires very Low pH:", data[data['ph'] < 4]['label'].unique())
print("Crops which requires very High pH:", data[data['ph'] > 9]['label'].unique())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.23953695458593055, 'fraction_numerical': 0.015265233430861214, 'mean_word_length': 4.5640481245576785, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '279541', 'license': 'MIT', 'n_tokens_mistral': 2778, 'n_tokens_neox': 2538, 'n_words': 514, 'path': 'sow-smart.ipynb', 'repo_name': 'kalpadhwaryu/sow-smart-ML', 'size': '7861'}