Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas replace values in column based on condition

In [41]:
df.loc[df['First Season'] > 1990, 'First Season'] = 1
df

Out[41]:
                 Team  First Season  Total Games
0      Dallas Cowboys          1960          894
1       Chicago Bears          1920         1357
2   Green Bay Packers          1921         1339
3      Miami Dolphins          1966          792
4    Baltimore Ravens             1          326
5  San Franciso 49ers          1950         1003
Comment

pandas replace values based on condition

df.loc[df['First Season'] > 1990, 'First Season'] = 1
Comment

replace values in a column by condition python

df.loc[df['employrate'] > 70, 'employrate'] = 7
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

panda replace row values based on condition in some existing column

df['column'].mask(df['column'] == 'original_value', new_value, inplace=True)
Comment

replace pandas column values based on condition

d.loc[d["conditionDisplayName"] == "Brand New", "conditionDisplayName"] = 6
d.loc[d["conditionDisplayName"] != "Brand New", "conditionDisplayName"] = 4
Comment

PREVIOUS NEXT
Code Example
Python :: how to display csv in pandas 
Python :: how to import from parent directory 
Python :: df .sort_values 
Python :: how to use global variable in python 
Python :: how to count the occurrence of a word in string python 
Python :: python scraping 
Python :: df dropna 
Python :: how to play mp3 files using vlc python library 
Python :: delete virtual environment in python windows 
Python :: python how to remove commas from string 
Python :: get context data django 
Python :: find different between list 
Python :: how to remove spaces in string in python 
Python :: remove element from list 
Python :: python find smallest value in 2d list 
Python :: pandas data profiling 
Python :: python mixins 
Python :: Python Program to Find Armstrong Number in an Interval 
Python :: alpaca api python wrapper 
Python :: count characters in string python 
Python :: hashing vs encryption vs encoding 
Python :: generate random token or id in django 
Python :: python how to get the folder name of a file 
Python :: split datetime to date and time pandas 
Python :: Python Format date using strftime() 
Python :: random split train test in python 
Python :: write binary file in python 
Python :: django create object with default today date 
Python :: python named group regex example 
Python :: how to make a multiple choice quiz in python with tkinter 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =