Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

change column value based on another column pandas

# Changes the 'is_electric' column based on value in the 'type' column
# If the 'type' column == 'electric' then the 'is_electric' becomes 'YES'
df['is_electric']= df['type'].apply(lambda x: 'YES' if (x == 'electric') else 'NO') 
Comment

replace column values/create new column based on another column values/condition in Pandas

df['New Column'] = np.where(df['A']==0, df['B'], df['A'])
Comment

PREVIOUS NEXT
Code Example
Python :: python decision tree classifier 
Python :: create an empty array numpy 
Python :: binary to decimal python 
Python :: python argparse argument without value 
Python :: text generate gpt 2 huggingface 
Python :: python even or odd 
Python :: lamda in pyton 
Python :: flask abort 
Python :: selenium python tkinter 
Python :: python3 tuple 
Python :: how to duplicate a column pandas 
Python :: python string to tuple 
Python :: python regex match until first occurrence 
Python :: remove dups in list of tuples 
Python :: Python basic discord bot 
Python :: 2d list in python 
Python :: Python Read the CSV file 
Python :: if key not in dictionary python 
Python :: get hex code of character python 
Python :: python server 
Python :: convert number to reversed array of digits python 
Python :: run python script without .py 
Python :: pandas count occurrences of certain value in row 
Python :: Iterate through string in python using for loop and rang 
Python :: how to change order of attributes of an element using beautiful soup 
Python :: every cell change comma to point pandas 
Python :: list comprehensions 
Python :: python scipy put more weight to a set value in curve_fit 
Python :: get single batch from torch data loader 
Python :: enumerate 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =