Python

Home Page My Research Works & Pulbications Data Python Utils Many Stuff

Python Utils

Bellow there are some useful scripts to work with python.
NOTE: Page in development, I put some simple examples to test the layout!


How to easily get some variable from a large data table:


    def getvar(param=None,File=None,HEADER=0):
        """
        Get a numerical variable from a table.
        HEADER: if == 1, display the file's header.
        """
        infile = open(File, 'r')
        firstLine = infile.readline()
        header=firstLine.split(',')
        if HEADER==1:
            print header
        else:
            ind=header.index(param)
            return np.loadtxt(File,usecols=(ind),comments="#", delimiter=",", unpack=False)
                    

How to easily get some string variable from a large data table:


    def getstr(string,File):
        """
        Get a string variable.
        """
        infile = open(File, 'r')
        firstLine = infile.readline()
        header=firstLine.split(',')
        ind=header.index(string)
        return np.loadtxt(File,dtype='str',usecols=(ind),comments="#", \
            delimiter=",", unpack=False)
                    

...