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

Set value of dataframe using condition

time_sin_grad[time_sin_grad < 0] = 0
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 :: count number of each item in list python 
Python :: How to Count occurrences of an item in a list in python 
:: effektivwert python 
Python :: python define an array of dictonary 
Python ::  
Python :: pandas dataframe get number of occurrence in column 
Python :: Image Watermarking in python 
Python :: del all variables python 
Python :: python flatten list 
Python :: sys.path.append python 
::  
Python ::  
Python :: check if point is inside polygon python 
Python ::  
Python :: how to close a flask web server with python 
Python :: first and last digit codechef solution 
Python :: Transform networkx graph to dataframe 
::  
Python :: pandas dataframe filter 
:: how to count number of columns in dataframe python 
Python :: python del 
:: python dict for k v 
Python :: try except finally python 
::  
Python :: access row of dataframe 
Python :: ignore pytest errors or warnings 
Python :: python create directory if non existent 
Python :: python array append 
Python :: kivy button on click 
Python ::  
ADD CONTENT
Topic
Content
Source link
Name
1+7 =