Drop duplicates, keep most recent date in a Pandas dataframe
Try: df.sort_values(‘DATE_CHANGED’).drop_duplicates(‘STATION_ID’,keep=’last’)
Try: df.sort_values(‘DATE_CHANGED’).drop_duplicates(‘STATION_ID’,keep=’last’)
What we can do is use nunique to calculate the number of unique values in each column of the dataframe, and drop the columns which only have a single unique value: In [285]: nunique = df.nunique() cols_to_drop = nunique[nunique == 1].index df.drop(cols_to_drop, axis=1) Out[285]: index id name data1 0 0 345 name1 3 1 1 … Read more
>>> from itertools import groupby >>> L = [0, 0, 0, 3, 3, 2, 5, 2, 6, 6] >>> grouped_L = [(k, sum(1 for i in g)) for k,g in groupby(L)] >>> # Or (k, len(list(g))), but that creates an intermediate list >>> grouped_L [(0, 3), (3, 2), (2, 1), (5, 1), (2, 1), (6, … Read more
Simply: DF.groupby(DF.index).first()
string1 = “calvin klein design dress calvin klein” words = string1.split() print (” “.join(sorted(set(words), key=words.index))) This sorts the set of all the (unique) words in your string by the word’s index in the original list of words.
While Scott Barta’s answer is correct, is lacks a simple and common solution: just add android { packagingOptions { exclude ‘META-INF/DEPENDENCIES’ exclude ‘META-INF/NOTICE’ exclude ‘META-INF/LICENSE’ exclude ‘META-INF/LICENSE.txt’ exclude ‘META-INF/NOTICE.txt’ } } to your build.gradle to ignore those duplicates.
You could go though each of the items (the key value pair) in the dictionary and add them into a result dictionary if the value was not already in the result dictionary. input_raw = {112762853378: {‘dst’: [‘10.121.4.136’], ‘src’: [‘1.2.3.4’], ‘alias’: [‘www.example.com’] }, 112762853385: {‘dst’: [‘10.121.4.136’], ‘src’: [‘1.2.3.4’], ‘alias’: [‘www.example.com’] }, 112760496444: {‘dst’: [‘10.121.4.136’], ‘src’: [‘1.2.3.4’] … Read more
You could modify your INSERT to be something like this: INSERT INTO tablename (tag) SELECT $tag FROM tablename WHERE NOT EXISTS( SELECT tag FROM tablename WHERE tag = $tag ) LIMIT 1 Where $tag is the tag (properly quoted or as a placeholder of course) that you want to add if it isn’t already there. … Read more
Sample SQL FIDDLE 1) Use CTE to get max ship code value record based on ARDivisionNo, CustomerNo for each Customers WITH cte AS ( SELECT*, row_number() OVER(PARTITION BY ARDivisionNo, CustomerNo ORDER BY ShipToCode desc) AS [rn] FROM t ) Select * from cte WHERE [rn] = 1 2) To Delete the record use Delete query … Read more