Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

add a value to an existing field in pandas dataframe after checking conditions

# Create a new column called based on the value of another column
# np.where assigns True if gapminder.lifeExp>=50 
gapminder['lifeExp_ind'] = np.where(gapminder.lifeExp >= 50, True, False)
gapminder.head(n=3)
Comment

add a value to an existing field in pandas dataframe after checking conditions

gapminder['gdpPercap_ind'] = gapminder.gdpPercap.apply(lambda x: 1 if x >= 1000 else 0)
gapminder.head()
Comment

PREVIOUS NEXT
Code Example
Python :: copy directory from one location to another python 
Python :: python date to timestamp 
Python :: django include all columns admin show 
Python :: lowercase all text in a column 
Python :: blender 2.8 python set active object 
Python :: python comment block 
Python :: python infinity 
Python :: count dictionary keys 
Python :: most common value in a column pandas 
Python :: python logging into two different files 
Python :: pandas lamda column reference 
Python :: python shortest distance between two points 
Python :: python 3 replace all whitespace characters 
Python :: python dict to dataclass 
Python :: python max key dictionary key getter 
Python :: python random list of integers without repetition 
Python :: how to create a python script to automate software installation? 
Python :: discord.py how get user input 
Python :: python sort class by attribute 
Python :: pil img to pdf 
Python :: type string python 
Python :: combine dataframes with two matching columns 
Python :: pandas dataframe froms string 
Python :: python relative file path doesnt work 
Python :: file.open("file.txt); 
Python :: python tuple vs list 
Python :: check if point is inside polygon python 
Python :: what is seaborn in python 
Python :: norm in python 
Python :: try catch in python 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =