How do I separate out unique rows in a list that has both a datetime and float column?
Question: I'm relatively new to Python, and I am having trouble separating out unique
rows from a data set that I had recently converted into lists. I broke
separated out the data's unixtime recordings and converted them into datetime.
Then when I recombined the data into a list I tried to separate out the unique
rows of data. But instead I get the error.

    
    
    [[[datetime.datetime(2014, 6, 20, 0, 0) -16.0]
      [datetime.datetime(2014, 6, 20, 0, 0) -16.0]........
    

Traceback (most recent call last):

    
    
    File "C:\Users\lenovo\Favorites\Microsoft 网站\Downloads\OTdataparser.py", line 33, in <module>
        indicies = np.unique(okdat, return_index = True) #<-- NOT WORKING
      File "C:\Python27\lib\site-packages\numpy\lib\arraysetops.py", line 180, in unique
        perm = ar.argsort(kind='mergesort')
    TypeError: can't compare datetime.datetime to float
    

My script is below.

    
    
    import numpy as np
    from datetime import datetime
    import matplotlib.pyplot as plt
    import math
    
    
    ds5 = np.genfromtxt("gpsdata.dat.140620", delimiter = '',
                        usecols = (2,4,5), dtype = object)
    
    print ds5
    
    ds = np.array([x for x in ds5 if x[0] == "06/20/2014"])
    dot = ds[:,2].astype(float)
    
    print ds
    
    rndsht = np.genfromtxt(ds[:,1], delimiter = ".", dtype = float) #Rm decimal
    print rndsht
    
    
    dutc = np.array([datetime.utcfromtimestamp(x) for x in rndsht[:,0]])
    
    print dutc
    #dutc = np.array([datetime.utcfromtimestamp(x) for x in ds[:,1].astype(float)])
    
    okdat = np.dstack((dutc,dot))
    #okdat.astype(object)
    
    print okdat
    
    #indicies = np.unique(dutc, return_index=True) #<-- WORKS! BUT okdat??
    #print indicies
    indicies = np.unique(okdat, return_index = True) #<-- NOT WORKING 
    print indicies
    
    #Can't figure out how to use indicies to limit dot
    


Answer: You could write your own unique function.

Here is quick example (you can probably do better). Note that is doesn't
preserve order, but you could use insert and do that.

def

    
    
    def unique(data):
        x = 0
    
        while x < len(data):
            i = data[x]
    
            c = 0
    
            while (i in data):
                c += 1
    
                data.remove(i)
            data.append(i)
    
            if (c <= 1):
                x += 1
        return data
    

