A Byte of my 2.2-lb Brain

Just sharing stuff…

Twitter Datetime

Twitter’s “CREATED_AT” format looks something like this Wed Mar 04 02:14:57 +0000 2015. To convert this to Python’s datetime format, simply use datetime.strptime(). If the tweets are stored in a … Continue reading

May 28, 2015 · Leave a comment

Obtaining Geolocation Details using GeoPy

The variables cdo, manila, and cebu are of type geopy.location.Location with the following attributes: address, altitude, latitude, longitude, point, and raw. To access these information, for Cagayan de Oro, for … Continue reading

May 17, 2015 · Leave a comment

Add Multiple Columns to Pandas Dataframe from Function

If you have a pandas data frame mydf that has, for example, two columns mydate and mytime (both are of type datetime), to add three more columns: hour, weekday, and … Continue reading

May 5, 2015 · Leave a comment

Malformed Database Disk Image

Every now and then, I encounter malformed database disk images, especially with sqlite3 files. DatabseError: database disk image is malformed To fix the error, the following methods worked for me. … Continue reading

May 2, 2015 · Leave a comment

GraphTool

For a few years now, I have been using NetworkX in all works related to networks. It’s a beautiful Python package and I love it. NetworkX is a Python language … Continue reading

April 28, 2015 · Leave a comment

dplyr::mutate()

One of my most favorite functions in [R] is dplyr::mutate(). The dplyr package is a very useful package with functions designed for data manipulation operations. It is also interesting that … Continue reading

April 22, 2015 · Leave a comment

pandas groupby Function

Grouping To group data frame elements by column, say group data frame df by Column 1, use To group by multiple columns, the argument for the `pandas.groupby()` function would now … Continue reading

April 20, 2015 · Leave a comment

Sorting Dictionaries in Python

Sort by Values Here’s a code snippet to sort dictionaries by their values. The output is a list: [(‘papaya’, 2), (‘avocado’, 3), (‘apple’, 10), (‘banana’, 12)] To reverse the list … Continue reading

April 17, 2015 · Leave a comment

MacPorts and Python 2.7

First things first, download MacPorts here—make sure you download the correct version for your OSX (e.g. Yosemite, Mavericks, Mountain Lion, etc.). Then install. Once the port command is working, you … Continue reading

April 14, 2015 · Leave a comment

Source Code on WordPress

Exploring some code syntax highlighting on WordPress.com. Fun! Python R C++

April 8, 2015 · Leave a comment