import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline

mvt = pd.read_csv('../../data/mvt2015_2017.csv')
mvt.head(3)

"""
Explanation: Analysis of Motor Vehicle Thefts in Chicago
The data about motor vehicle thefts in chicago are taken from the Chicago Data Portal
End of explanation
"""


# TODO how many entries

# TODO different Location Descriptions

"""
Explanation: Exercise 0
Inspect the mvt-data (columns, colum-types, first rows...)

How many entries are there?
How many different Location Descriptions exists?
End of explanation
"""


# TODO

"""
Explanation: Exercise 1
Draw a histogram to investigate, which locations (Location Description) are the top 10  theft hot spots horizontally.
Exercise 1.1
Use Dataframe/Series.plot to plot the histogram (barchart) horizontally.
Note:<br>
DataFrame.plot.hist() can only work with numerical x-values. If you don't want to convert the 'Location Descriptions' to a numeric value, you may want to use Series.value_counts().plot instead.
End of explanation
"""


import seaborn as sns
# TODO your code goes here

"""
Explanation: Exercise 1.2
Install seaborn:
bash
conda install seaborn
Use the Countplot to show the frequencies of thefts at the single location (descriptions).
Plot the top 10 hot spots horizontally.
See also Plotting with categorical data for further information about how to show categorical data with seaborn.
Hint<br>
- you still have to use value_counts() to find the top10 hot spots
- set sns.countplot-order parameter to the top10 hot spots
End of explanation
"""


# TODO Date to pandas.DateTime

# TODO Date as index

# TODO WeekDay as new ordered categorical column

"""
Explanation: Exercise 2
Investigate, at which weekdays/which hour the most thefts happen.
Exercise 2.1

Convert Date to pandas.DateTime,
set Date as index and
add a further column Weekday (which is the weekday of Date), which is an ordered category (['Monday' , 'Tuesday'...).<br> 
Check 
the Pandas Docs
and the Advanced Pandas Primer
on how to convert to an ordered category.

Note:<br>
Defining the weekday as categorical is required to get the plots in the further exercises ordered by weekday.
End of explanation
"""


# TODO group by Weekday

# Plot group (barh)

"""
Explanation: Exercise 2.2
Count the thefts by weekday and<br>
make a corresponding histogram (barchart)
At which weekday happen the most thefts?
End of explanation
"""


# TODO add additional column Hour

# TODO group by Weekday,Hour and aggregate size
# TODO reset index (for pivot only)
# TODO pivot (or unstack)

# make a line-plot: count over Hour by Weekday(==Groups)

"""
Explanation: Exercise 2.3

Add a further column Hour (which is the hour of Date) to the mvt-dataframe.
make a line-plot - 1 line per weekday - of number of thefts (y-axis) over the Hours (x-axis).<br>
  The plot should look similar to:
  

Note<br>
To be able to plot without looping, you may want to
1. groupby(['Weekday','Hour']) and aggregate size
2. reset_index of the aggregate and pivot or unstack, so that index are the 24 Hours, the columns are the Weekdays and the values are the counts.
Please check the 
  - Pandas pivot Documentation on how pivot works or
  - Pandas unstack Documentation on how unstack works.
The pivot-table should look similar to:<br>
<div>
<table border="1">
<thead>
<tr style="text-align: left;">
  <th>Weekday</th>
  <th>Monday</th>
  <th>Tuesday</th>
  <th>Wednesday</th>
  <th>Thursday</th>
  <th>Friday</th>
  <th>Saturday</th>
  <th>Sunday</th>
</tr>
<tr>
  <th>Hour</th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
</tr>
</thead>
<tbody>
<tr>
  <th>0</th>
  <td>76</td>
  <td>..</td>
  <td>..</td>
  <td>..</td>
  <td>..</td>
  <td>..</td>
  <td>234</td>
</tr>
<tr>
  <th>1</th>
  <td>126</td>
  <td>..</td>
  <td>..</td>
  <td>..</td>
  <td>..</td>
  <td>..</td>
  <td>...</td>
</tr>
</tbody>
</table>
</div>
End of explanation
"""


# TODO

"""
Explanation: Exercise 2.4
Draw a heatmap with seaborn.heatmap:<br>
x-axis=Hours, y-axis=Weekday, fill=count
At which weekday/time are the most thefts committed?
Additional<br>
Play with color palettes for parameter cmap
End of explanation
"""


