Skip to content

Instantly share code, notes, and snippets.

View acviana's full-sized avatar

Alex C. Viana acviana

View GitHub Profile

Keybase proof

I hereby claim:

  • I am acviana on github.
  • I am acv (https://keybase.io/acv) on keybase.
  • I have a public key ASARGh9PzYhkW7ifTJAzViwVjjlHNXkPKGOIS5vBgON-fgo

To claim this, I am signing this object:

Data Analysis in the Shell

The shell provides several utilities that aren't great for large scale analysis but can be useful for quick data analysis.

Reading Data

There are various ways to display human-readable file.

  • less
@acviana
acviana / 2014-08-29-swc-ufrgs-python-demo.md
Last active August 29, 2015 14:05
Python for data analysis demo for UFRGS Software Carpentry Workshop on 2014-08-29

Numpy

Load the Numpy module:

import numpy as np

Use the Numpy genfromtxt function to load the data, manually defining the column names.

Unix Commands

How many requests are in the log file?

$ wc example.log
 9999999 173321954 1629465770 example.log

9,999,999 assuming 1 per line.

What percentage of requests from iPads resulted in HTTP status code 500?

#!/usr/bin/env python
import requests
import json
with open('driver-en.js', 'r') as f:
data = f.readlines()
output_list =[]
for counter, record in enumerate(data):
@acviana
acviana / sqlalchemy_demo.py
Created June 20, 2013 03:41
This module is a script demonstrating some basic features of the SQLAlchemy ORM declarative base. First shared with the Baltimore Python meetup 06/19/13.
'''
This module is a script demonstrating some basic features of the
SQLAlchemy ORM declarative base. First shared with the Baltimore
Python meetup 06/19/13.
It requires either a MySQL instance or SQLite to run as written but
you can modify it run with any SQL flavor SQLAlchemy supports.
Alex C. Viana
alexcostaviana [at] gmail [dot] com
@acviana
acviana / check_date_format.py
Created October 2, 2012 00:51
This is a function to check if a date string is in 'MMM DD YYYY' format, e.g. 'Oct 1 2012'.
def check_date_format(date):
'''
Check if that date string has a 'MMM DD YYYY' format. Return a boolean.
'''
output = True
if isinstance(date,unicode) == False:
return False
month, day, year = date.split()
if set(month) >= set(string.ascii_letters):
return False