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 :: playsound module in python 
Python :: python async threading 
Python :: opencv set window size 
Python :: python strftime utc offset 
Python :: python iterate letters 
Python :: Set column as index with pandas 
Python :: rename columns in dataframe 
Python :: get values using iloc 
Python :: python list comprehension double for 
Python :: Pyo example 
Python :: tkinter gui grid and frame 
Python :: python filter a dictionary 
Python :: pandas replace na with 0 
Python :: how to know where python is installed on windows 
Python :: generate all parameters combination python 
Python :: roll longitude about zero 
Python :: python3 return a list of indexes of a specific character in a string 
Python :: how to print all combinations of a string in python 
Python :: python boxplot show mean 
Python :: replace error with nan pandas 
Python :: python pandas convert comma separated number string to integer list 
Python :: print() in python 
Python :: Socket Programming Client Side 
Python :: how to sort in greatest to least python 
Python :: selenium how to handle element not found python 
Python :: python datetime without seconds 
Python :: get requests from python 
Python :: grab a href using beuatiful soup 
Python :: url in form action django 
Python :: python csv reader skip header 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =