Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

replace pandas column values based on condition

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

Change one value based on another value in pandas

df.loc[df.ID == 103, ['FirstName', 'LastName']] = 'Matt', 'Jones'
//or
import pandas
df = pandas.read_csv("test.csv")
df.loc[df.ID == 103, 'FirstName'] = "Matt"
df.loc[df.ID == 103, 'LastName'] = "Jones"
Comment

update dataframe based on value from another dataframe

In [27]:

df.loc[df.Name.isin(df1.Name), ['Nonprofit', 'Education']] = df1[['Nonprofit', 'Education']]
df
Out[27]:
  Name  Nonprofit  Business  Education
0    X          1         1          0
1    Y          1         1          1
2    Z          1         0          1
3    Y          1         1          1

[4 rows x 4 columns]
Comment

pandas replace values from another dataframe

In [36]:
df['Group'] = df['Group'].map(df1.set_index('Group')['Hotel'])
df

Out[36]:
         Date  Group  Family  Bonus
0  2011-06-09  Jamel  Laavin    456
1  2011-07-09  Frank  Grendy    679
2  2011-09-10   Luxy  Fantol    431
3  2011-11-02  Frank  Gondow    569
Comment

PREVIOUS NEXT
Code Example
Python :: python machine learning model 
Python :: python time 
Python :: python why call super(class).__init__() 
Python :: split string to list 
Python :: python random choices weights 
Python :: cookies in django 
Python :: numpy make 2d array 1d 
Python :: how to set global variable in python function 
Python :: Converting (YYYY-MM-DD-HH:MM:SS) date time 
Python :: python tuple 
Python :: python dataframe appendisnt showing 
Python :: how delete element from list python 
Python :: how to chang your facebook name 
Python :: add favicon in django admin 
Python :: jsonresponse django 
Python :: how to round to the nearest tenth in python 
Python :: what is index in list in python 
Python :: replace in lists py 
Python :: python requests response 503 
Python :: Subset data frame by date 
Python :: what is queryset in django 
Python :: how to find missing item in a list 
Python :: ord() in python 
Python :: tkinker 
Python :: how print array in python with clean dublication 
Python :: how list ul li with python scraping 
Python :: intersection of two lists using set method 
Python :: pygame pin to top 
Python :: usign signal files django 
Python :: python enumerate() 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =