Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Renaming row value in pandas

# if the row value in column 'is_blue' is 1 
# Change the row value to 'Yes' 
# otherwise change it to 'No'
df['is_blue'] = df['is_blue'].apply(lambda x: 'Yes' if (x == 1) else 'No') 


# You can also use mapping to accomplish the same result
# Warning: Mapping only works once on the same column creates NaN's otherwise
df['is_blue'] = df['is_blue'].map({0: 'No', 1: 'Yes'})  
Comment

rename row pandas

>>> df.rename({1: 2, 2: 4}, axis='index')
   A  B
0  1  4
2  2  5
4  3  6
Comment

PREVIOUS NEXT
Code Example
Python :: remove grid in plt 
Python :: how to order randomly in django orm 
Python :: pygame font 
Python :: how to find the neighbors of an element in matrix python 
Python :: python - sort dictionary by value 
Python :: how to add numbers in python using for loop 
Python :: convert transformation matrix to pose ros 
Python :: access to numbers in classification_report - sklearn 
Python :: sort list of dictionaries python by value 
Python :: pandas series draw distribution 
Python :: procfile flask 
Python :: convert all values in array into float 
Python :: get parameters flask 
Python :: python implode list 
Python :: py random list integers 
Python :: print on two digit python format 
Python :: python max absolute value 
Python :: python list of random float numbers 
Python :: how to make a alert box in python 
Python :: import tknter 
Python :: Jun 12, 2007 hoteis othon 
Python :: requirements.py for flask 
Python :: flask app example 
Python :: how to convert async function to sync function in python 
Python :: Finding the sum of even Fibonacci numbers less than or equal to given limit 
Python :: set threshold resnet18 pytorch 
Python :: sort list of files by name python 
Python :: wait for page to load selenium python 
Python :: json load from file python 3 
Python :: array must not contain infs or NaNs 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =