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 :: view all columns pandas 
Python :: pandas nan values in column 
Python :: python for/else 
Python :: sorting a list of dictionaries 
Python :: joins in pandas 
Python :: python - calculate the value range on a df 
Python :: font in tkinter 
Python :: regex remove all html tags except br python 
Python :: seed python 
Python :: python install minio 
Python :: break all loops 
Python :: extract nonzero array elements python 
Python :: python variable 
Python :: multiprocessing print does not work 
Python :: python cli click 
Python :: python last n list elements 
Python :: python compare floats 
Python :: how to check if there is a word in a string in python 
Python :: python loop through dictionary 
Python :: pandas count values by column 
Python :: fibonacci series using recursion in python 
Python :: int to alphabet letter python 
Python :: pandas remove outliers 
Python :: python list add element to front 
Python :: pandas drop duplicate keep last 
Python :: how to write variables in python 
Python :: ffill dataframe python 
Python :: read data from s3 bucket python 
Python :: spark list tables in hive 
Python :: code challenges python 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =