Panda Time index vs DateTime and Inconveniences

Sometimes convenience becomes a handicap. Saw this first hand later last month.

Was so used to using Pandas DataFrame and the Timeindex object that when I had to move back to a system which didn’t have pandas I was struggling to get a simplified day of year, day of week and week of year from python’s standard datetime module.

Here is how all this available in Pandas from a Timeindex column or index.

If your looks like this, with index as time

You can get all the convenience functions like this

However, this gave an opportunity to explore datetime and here is the code to get all this and more from date time.

import datetime
day_of_year = today.timetuple().tm_yday

Inconveniences are good; they always end up teaching you something.


Updated Binary STL File Reader


A recent comment on the post titled binary stl file reader in numpy prompted me to revisit the code and while I was looking at it , I updated the same for code to view the loaded stl file.

The above picture shows the result.

The code as usual available on github from here

from binarySTLreader import BinarySTL,ShowSTLFile

Joint plot with Matplotlib

Today I am releasing a simple module to create joint plot with Matplotlib on github. Joint plot is available in the excellent seaborn library but unfortunately it’s not always available on many systems. Recently I needed this functionality, so wrote this simple module with matplotlib.

The functionality is almost similar to seaborn but with limited feature. This has helped me in my work, releasing it in the hope that others might find it useful.

Sample usage:

Import Jointplot

Find the code at this github repository.

Quarterly Results Analysis with Python

Every quarter when results come out, I spend sufficient hours looking at the financial results of the stocks I am tracking to elicit nagging comments from my better half. So developed this simple python script which does the analysis and generates me the PDF which I email to myself to look at during office commute.

The code as always is available at my github page here.

Some sample plots

Intend to update the scripts for other analysis as and when I get some time.

OD Command in Windows with Python

I have seen OD command for last two years but had never bothered to look it up. It always remained under the surface.

Life went on well without it, until now.

During a recent debugging crisis, had to resort to this command for an efficient way to check binary results. All the while had to go to Linux and copy the files. This is when I knew I have to see what this OD is?

OD is octal dump. Simple functionality, don’t know if there is a windows equivalent. So before searching for a windows equivalent, I knew I can replicate this in python and here’s my first attempt.

Works for me and suits my requirement. Not an entire mimic of actual OD command but if you are looking for long and double precision values, this does the job.

I have kept the command line arguments similar to the actual OD command. Here’s a simple demo.

As always, the code is available from my github repo here. Hope to add more functionality as and when I get more time. Please free to fork and play around.

Special thanks to Andy for introducing the command and helping me make sense of the important arguments.

Get Mount Drive from mount path in windows

Things that are simple in Linux and UNIX based system always end up becoming a head ache in windows, but unfortunately most of our work-life runs on windows.

And if you don’t have admin rights to install specialized modules in your python installation, then here’s a hacked version of routine that should do the job.

def get_mount_drive(path):
    os.system(r'net use > t.txt')
    for line in lines:
    if path in line:
       return lines.split()[1]
    return None

Few Python Regex for FORTRAN Code


Most of my day job involves Fortran code and finding quick details is a regular need. Here are four regex in python that I have been using for some time now. Sharing it here.

To Find Subroutines and Functions

 import re procedule_name=re.compile(r'\s*(RECURSIVE)?\s+(SUBROUTINE|FUNCTION)\s+\S+\(.*',re.IGNORECASE) 


To Find All Call Statements




To Find Variables (Integer, Double Precision, Logical, Real)



To Find Character Variables