Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

fill a column based on values in another column pandas

df['Normalized'] = np.where(df['Currency'] == '$', df['Budget'] * 0.78125, df['Budget'])
Comment

Fill column based on values of another column

conditions = [
    (df['Age'] < 20),
    (df['Age'] >= 20) & (df['Age'] < 40),
    (df['Age'] >= 40) & (df['Age'] < 59),
    (df['Age'] >= 60)
]

values = ['<20 years old', '20-39 years old', '40-59 years old', '60+ years old']

df['Age Group'] = np.select(conditions, values)

print(df)
Comment

PREVIOUS NEXT
Code Example
Python :: python getting line count 
Python :: python linear interpolation 
Python :: date to timestamp python 
Python :: create a flask app 
Python :: pip not recognized 
Python :: py search and get objects from array 
Python :: private attributes python 
Python :: python re split 
Python :: pandas get attribute of object 
Python :: correlation meaning 
Python :: join list of string into a single string with comma 
Python :: python cron job virtualenv 
Python :: pydrive download by url 
Python :: Merge two Querysets in Python Django while preserving Queryset methods 
Python :: what is indentation in python 
Python :: python Sum of all the factors of a number 
Python :: how to make a new column with explode pyspark 
Python :: how to draw dendrogram in python 
Python :: Python Sum of an array in NumPy 
Python :: return array of sorted objects 
Python :: sort function in pandas dataframe to sort specific properties 
Python :: operators in python 
Python :: value list in django 
Python :: for in print pyhton 
Python :: random number generator python 
Python :: mixpanel export api 
Python :: can list hold different data types in python 
Python :: django venv activate 
Python :: hide text in plot 
Python :: boto 3 list EMR 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =