# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/kvinne-anc/India-Rainfall-and-Commodities-Project/blob/main/India_Rainfall_DataGeoPandas.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + id="M4BYRHcC_7lZ" colab={"base_uri": "https://localhost:8080/", "height": 1000} outputId="3ec44b65-3620-43b7-a793-9a70e34470a2"
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# !pip install category_encoders==2.*
# !pip install pandas-profiling==2.*


# + id="prlvlop6R-DE" colab={"base_uri": "https://localhost:8080/", "height": 1000} outputId="324a9e07-93fc-4ddc-9775-bd32e5cbfb6c"
# %%time 

# Important library for many geopython libraries
# !apt install gdal-bin python-gdal python3-gdal 
# Install rtree - Geopandas requirment
# !apt install python3-rtree 
# Install Geopandas
# !pip install git+git://github.com/geopandas/geopandas.git
# Install descartes - Geopandas requirment
# !pip install descartes 
# Install Folium for Geographic data visualization
# !pip install folium
# Install plotlyExpress
# !pip install plotly_express

# + id="ppdv9iMOJKjN"
import zipfile
import shutil
from glob import glob
import os
import pandas as pd
import geopandas as gdp
import matplotlib.pyplot as plt
import numpy as np
from sklearn.model_selection import train_test_split


# + id="LYKmXlYBSPgC" colab={"base_uri": "https://localhost:8080/", "height": 222} outputId="397cec72-4499-4e1f-980b-2f507d8b4e1e"
# !pip install PyShp
# !pip install shapely

# + id="76pxppm6SXjW"
import fiona

# + id="Amj0ck0FM_q0"
from zipfile import ZipFile


# + id="AroO2vR6lRPC" colab={"base_uri": "https://localhost:8080/", "height": 1000} outputId="2a928580-fb85-4b48-dcd7-50e4c0fb9f81"
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn import metrics
import sys
if 'google.colab' in sys.modules:
    # !pip install category_encoders==2.*
    # !pip install pandas-profiling==2.*
    # !pip install plotly==4.*


# + id="NoBMfvnaULXz" colab={"base_uri": "https://localhost:8080/", "height": 50} outputId="b830fa73-5623-4df6-a410-69ea2c59d8ea"
# !unzip /content/commodity_trade_statistics_data.csv.zip

# + id="Ej4HaDSU0xcU" colab={"base_uri": "https://localhost:8080/", "height": 50} outputId="cac6ab15-ccf5-42a1-bcc5-b8c24a82ea14"
# !unzip /content/IndiaTemps.zip

# + id="VEtBGwta0xf3" colab={"base_uri": "https://localhost:8080/", "height": 50} outputId="7bf60a7f-4b34-45e1-92b0-0f5a36867ec5"
# !unzip /content/IndiaRain.zip

# + id="Zexn-0AwUL_m"
trade = pd.read_csv('/content/commodity_trade_statistics_data.csv')

# + id="qAim9LsKUMCR"
trade.head(5)

# + id="NBvChiB_aKPX"
trade_c = trade[['country_or_area','year','comm_code', 'flow', 'category' ,'trade_usd']]

# + id="74hiHitEUMFC"
India_ex=trade[trade['flow']=='Export']

# + id="1O5nwA96UMIa"
India_ex.head(5)

# + id="lM0nBXC3bxAZ"
India_ex.dtypes

# + id="tF0w6b_ybxIf"
India_ex.isnull().sum()

# + id="PnHwPu8ycQDX"
India = India_ex.drop('flow', axis=1)
India

# + id="-GNrJCKhkZQ5"
India['comm_code'].nunique

# + id="cnlI5F5Sk8Oj"
# Get indexes where name column has value Total
indexNames = India[India['comm_code'] == 'TOTAL'].index
 
# Delete these row indexes from dataFrame
India.drop(indexNames, inplace=True)

India

# + id="2e52Dfb9gbCs"
India_x = India.groupby('commodity').trade_usd.mean().reset_index(name='trade_usd')
India_x = India.nlargest(35000,'trade_usd').reset_index()
India_x

# + id="untQHLvfmbRI"
India_x.shape

# + id="qEZKVHN4lKrS"
cat_col = India_x.columns[India_x.dtypes=='object']

(cat_col)

# + id="03rVM1Wm0xt1"
India_x[cat_col] = India_x[cat_col].astype('category')

# + id="26jz7ruPhto6"
y = India_x['trade_usd']

# + id="gvEIEmW3h0LR"
x = India_x[['country_or_area', 'year']]

# + id="ndwj0nU-fDBl"
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=42)

# + id="FxnIN0jvfMaB"
x_train.shape

# + id="2LorWjBA3igS"
from sklearn.linear_model import LogisticRegression
from sklearn import metrics
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=42)
logreg = LogisticRegression()
logreg.fit(X_train, y_train)

# + id="ZxJj25Byoq6J"
#import category_encoders as ce
#from sklearn.impute import SimpleImputer
#from sklearn.ensemble import RandomForestClassifier
#from sklearn.pipeline import make_pipeline
#from sklearn.preprocessing import StandardScaler

#pipeline = make_pipeline(
 #   ce.OrdinalEncoder(),
  #  SimpleImputer(strategy='mean'), 
   # StandardScaler(), 
    #RandomForestClassifier(n_estimators=100, 
     #                          bootstrap = True,
      #                         max_features = 'sqrt')
)

# + id="EvCxr30fo-g4"
#pipeline.fit(x_train, y_train)

# + id="Cj6E7_A93jv1"


# + id="88CGfMyVijFN"
my_model = LinearRegression()

# + id="Lk_5pgzKjY5P"
my_model.fit(x_train, y_train)

# + id="hOvgILB9jZHW"


# + id="rTDYdmPmjZKz"


StarcoderdataJupyterScriptsDedupFiltered