Using pandas:
df = pd.DataFrame({'n':['d','a','b','c','c','a','d','b'], 'v':[1,2,1,2,2,1,1,1]})
How to rename elements in df.n , so that a changes to x , b to y , c to w and d to z , resulting in:
df.n
a
x
b
y
c
w
d
z
nv 0 z 1 1 x 2 2 y 1 3 w 2 ...
You can pass the dictionary of substitution values ββto the replace method:
In [11]: df['n'].replace({'a': 'x', 'b': 'y', 'c': 'w', 'd': 'z'}) Out[11]: 0 z 1 x 2 y 3 w 4 w 5 x 6 z 7 y Name: n, dtype: object In [12]: df['n'] = df['n'].replace({'a': 'x', 'b': 'y', 'c': 'w', 'd': 'z'})
Source: https://habr.com/ru/post/1499931/More articles:Endless loop - phpMySQL selects a query in where where - sqlPlugin execution does not apply to AppEngine lifecycle configuration - javahow to stop an already signed-in user to enter another browser - javaIE10 does not handle jquery file upload request - jqueryhow to count repetition of elements in a python list, django - pythonHow do I transfer Primefaces-Upload-Temp-Files files instead of doing a time-intensive process? - java404 mini crashing machine - many ruby-on-railsHandling OnCheckedChanged Checkbox event using Javascript - javascriptHow to upload files without turning them into a temporary file? (Core JSF NetBeans Interfaces) - file-uploadAll Articles