Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas replace duplicates unique identifier

import pandas as pd
import numpy as np
data = {'Name':['Tom', 'Tom', 'Jack', 'Terry'], 'Age':[20, 21, 19, 18]} 
df = pd.DataFrame(data)

nth = ['First', 'Second', 'Third', 'Fourth']

def prefix(d):
    n = len(d)
    if n > 1:
        return d.radd([nth[i] for i in range(n)])
    else:
        return d

df.assign(Name=df.groupby('Name').Name.transform(prefix))

          Name  Age
0     FirstTom   20
1    SecondTom   21
2         Jack   19
3        Terry   18
​
Comment

PREVIOUS NEXT
Code Example
Python :: k-means clustering and disabling clusters 
Python :: mechanize python #6 
Python :: mechanize python fill 
Python :: how to implement nfa in python 
Python :: effient way to find prime no inpython 
Python :: djago get settings 
Python :: how to visualize pytorch model filters 
Python :: append to a list without intializing 
Python :: iterate 
Python :: multiplication objects 
Python :: compute difference in dates after groupby 
Python :: create new model description odoo 
Python :: # check built-in function using dir() 
Python :: scipy z value to pvalue 
Python :: cornell hotel sustainability benchmarking index 
Python :: how delet an obj from memori in python 
Python :: restrict memory use python code 
Python :: auto reload exml odoo 13 
Python :: Validation using voluptuous python library 
Python :: matplotlib pie turn small pct labels off 
Python :: merge sort dictionary python 
Python :: python replace every space, dash and parentheses into underscore 
Python :: docstring return list of tuple 
Python :: python ordereddict initialization 
Python :: Python NumPy atleast_1d Function Example when inputs are in high dimension 
Python :: python access to vraiable in another classe 
Python :: Python NumPy block Function Syntax 
Python :: Python NumPy dsplit Function Syntax 
Python :: __ge__ 
Python :: get forex exchange rates in python 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =