There are two main insights we want to communicate.
Let us explore how we can communicate these insight visually.
In [1]:
# Import the library we need, which is Pandas and Matplotlib
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
# import seaborn as sns
In [2]:
# Set some parameters to get good visuals - style to ggplot and size to 15,10
plt.style.use('ggplot')
plt.rcParams['figure.figsize'] = (15, 10)
In [3]:
# Read the csv file of Monthwise Quantity and Price csv file we have.
df = pd.read_csv('MonthWiseMarketArrivals_clean.csv')
In [4]:
# Change the index to the date column
df.index = pd.PeriodIndex(df.date, freq='M')
In [5]:
# Sort the data frame by date
df = df.sort_values(by = "date")
In [6]:
# Get the data for year 2015
df2015 = df[df.year == 2015]
In [7]:
# Groupby on City to get the sum of quantity
df2015City = df2015.groupby(['city'], as_index=False)['quantity'].sum()
In [8]:
df2015City = df2015City.sort_values(by = "quantity", ascending = False)
In [9]:
df2015City.head()
Out[9]:
In [10]:
# Load the geocode file
dfGeo = pd.read_csv('city_geocode.csv')
In [11]:
dfGeo.head()
Out[11]:
In [12]:
dfCityGeo = pd.merge(df2015City, dfGeo, how='left', on=['city', 'city'])
In [13]:
dfCityGeo.head()
Out[13]:
In [14]:
dfCityGeo.plot(kind = 'scatter', x = 'lon', y = 'lat', s = 100)
Out[14]:
We can do a crude aspect ratio adjustment to make the cartesian coordinate systesm appear like a mercator map
In [15]:
dfCityGeo.plot(kind = 'scatter', x = 'lon', y = 'lat', s = 100, figsize = [10,11])
Out[15]:
In [16]:
# Let us at quanitity as the size of the bubble
dfCityGeo.plot(kind = 'scatter', x = 'lon', y = 'lat', s = dfCityGeo.quantity, figsize = [10,11])
Out[16]:
In [17]:
# Let us scale down the quantity variable
dfCityGeo.plot(kind = 'scatter', x = 'lon', y = 'lat', s = dfCityGeo.quantity/1000, figsize = [10,11])
Out[17]:
In [18]:
# Reduce the opacity of the color, so that we can see overlapping values
dfCityGeo.plot(kind = 'scatter', x = 'lon', y = 'lat', s = dfCityGeo.quantity/1000, alpha = 0.5, figsize = [10,11])
Out[18]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: