Created
July 24, 2014 04:18
-
-
Save sampathweb/4f3f800b952d2bf6868b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/env/python | |
from __future__ import print_function | |
import pandas as pd | |
# Read the csv | |
violations_df = pd.read_csv('violations-2012.csv') | |
# Covert Violations to datetime object | |
violations_df['violation_date'] = pd.to_datetime(violations_df['violation_date']) | |
violations_df['violation_date_closed'] = pd.to_datetime(violations_df['violation_date_closed']) | |
# Group by Category | |
category_group = violations_df.groupby('violation_category') | |
# Calcuate Min, Max and Value Counts | |
violation_min_date = category_group['violation_date'].min() | |
violation_max_date = category_group['violation_date'].max() | |
violation_count = category_group.size() | |
violations_result = pd.DataFrame({'violation_count': violation_count, | |
'violation_min_date': violation_min_date, | |
'violation_max_date': violation_max_date}) | |
print(violations_result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment