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 row values 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
Comment

pandas replace values based on condition

df.loc[df['First Season'] > 1990, 'First Season'] = 1
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 :: Adjusting Subplot Margins in Matplotlib 
Python :: how can item in list change in int in python 
Python :: Python Requests Library Get Method 
Python :: python how to change back to the later directory 
Python :: curl python 
Python :: python fillna with mode 
Python :: python function to scale selected features in a dataframe pandas 
Python :: value count in python 
Python :: set index in datarame 
Python :: as type in pandas 
Python :: pandas groupby apply list 
Python :: python requests response get text 
Python :: scipy euclidean distance 
Python :: django content type 
Python :: how to get dummies in a dataframe pandas 
Python :: sha512 python 
Python :: change colors markdown pyhton 
Python :: python repeting timer 
Python :: palindrome string python 
Python :: python opencv imresize 
Python :: pyplot width 
Python :: python classes 
Python :: try except keyerror 
Python :: os.chdir python 
Python :: python generate random string 
Python :: drop column from dataframe 
Python :: make a script run itself again python 
Python :: change shortcuts in pychar, 
Python :: list to dataframe 
Python :: how to connect an ml model to a web application 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =