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 :: Invalid comparison between dtype=datetime64[ns] and date filter 
Python :: python add attribute to class instance 
Python :: python convert object to json 
Python :: Python Frozenset operations 
Python :: creating dataframe 
Python :: ip validity checker python 
Python :: size array python 
Python :: np.eye 
Python :: read part of file pandas 
Python :: import fernet 
Python :: installing pip in pytho 
Python :: fakultät python 
Python :: User serializer in django rest framework 
Python :: rename keys in dictionary python 
Python :: reversed python 
Python :: find total no of true in a list in python 
Python :: how to create a virtual environment in python 
Python :: take first 10 row while reading csv python 
Python :: python comparison operators 
Python :: selenium python find element by class name with space 
Python :: pandas invert a boolean Series 
Python :: numpy transpose 
Python :: python ctypes maximize window 
Python :: python remove spaces from string 
Python :: groupby where only 
Python :: python list of dictionaries 
Python :: python discord embed link 
Python :: python scapy get mac of remote device 
Python :: python input character limit 
Python :: pandas line plot dictionary 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =