Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

make a condition statement on column pandas

df['color'] = ['red' if x == 'Z' else 'green' for x in df['Set']]
Comment

Pandas conditional collumn

import pandas as pd
import numpy as np

df = pd.DataFrame({'Type':list('ABBC'), 'Set':list('ZZXY')})
df['color'] = np.where(df['Set']=='Z', 'green', 'red')
print(df)
Comment

make a condition statement on column pandas

df.loc[df['column name'] condition, 'new column name'] = 'value if condition is met'
Comment

PREVIOUS NEXT
Code Example
Python :: time df.apply() python 
Python :: how to print all items in a list python 
Python :: remove first element from list 
Python :: how to update values in tkinter 
Python :: how to do randon in python 
Python :: days to int 
Python :: pandas separator are multiple spaces 
Python :: how to import pandas in python 
Python :: creating django project 
Python :: os.getcwd() python 3 
Python :: fillna not work 
Python :: BURGERS2 
Python :: np.eye 
Python :: python requests-session for websites with login 
Python :: python abc 
Python :: python new date 
Python :: webdriverwait python 
Python :: sum along axis python 
Python :: flask dockerize 
Python :: python create dataframe by row 
Python :: extract all capital words dataframe 
Python :: np ln 
Python :: how to download from url in python 
Python :: python constant 
Python :: python ssl 
Python :: add list to end of list python 
Python :: yield python 
Python :: how to use dictionary in python 
Python :: torch tensor to pandas dataframe 
Python :: django x-frame-options allowall 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =