Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

create new column with mask pandas

mask0 = (df['condition'] == 1)
mask1 = (df['condition'] == 0)

df.loc[mask0, 'newColumn'] = df.loc[mask0, 'otherColumn1']
df.loc[mask1, 'newColumn'] = df.loc[mask1, 'otherColumn2']
Comment

PREVIOUS NEXT
Code Example
Python :: create random phone number python 
Python :: add values to tuple python 
Python :: how to add column to the Dataframe in python 
Python :: python discord bot 
Python :: indexing python first and last 
Python :: Converting Dataframe from list Using a list in the dictionary 
Python :: get ticks pygame 
Python :: how to download from youtube in discord.py 
Python :: python set match two list 
Python :: uninstall a python package from virtualenv 
Python :: how to loop through pages of pdf using python 
Python :: switch between frames in tkinter 
Python :: big comments python 
Python :: gaierror at /members/register [Errno 11001] getaddrinfo failed 
Python :: tensorflow inst for python 3.6 
Python :: Add Cog to bot in Discord.py 
Python :: save pillow image to database django 
Python :: how to append to a dictionary in python 
Python :: python byte like to string 
Python :: inverse mask python 
Python :: try catch python with open 
Python :: push notification using python 
Python :: List comprehension if-else 
Python :: requests save file python 
Python :: python convert list of lists of strings to int 
Python :: how to make curl request python 
Python :: map a list to another list python 
Python :: ajouter element liste python 
Python :: Disctionary to Array 
Python :: dict map() 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =