Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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

PREVIOUS NEXT
Code Example
Python :: python how to add a new key to a dictionary 
Python :: python print ling line in print 
Python :: color module python 
Python :: python remove multiple element from list by index 
Python :: get dummies pandas 
Python :: join two strings python 
Python :: pandas check length of string 
Python :: discord embed python 
Python :: foreign key django createview 
Python :: insert a new row to numpy array in especific position 
Python :: create folders in python overwright existing 
Python :: repeat a condition n times one by one python 
Python :: how to make a static variable in python 
Python :: python mongodb connection 
Python :: how to find out the max and min date on the basis of property id in pandas 
Python :: create table numpy 
Python :: how to put my graph in tkinter interface 
Python :: python collection 
Python :: python unittest multiple test cases 
Python :: python check if string is float 
Python :: geopandas replace column name 
Python :: try except to specific line 
Python :: python divide and round away operator 
Python :: python cassandra 
Python :: python set workspace dir 
Python :: format numbers in column to percentage in python 
Python :: how to count the number of guesses in python 
Python :: python in kali linux 
Python :: # Python string capitalization 
Python :: python dataframe add rank column 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =