Answers for "change multiple values in an element pandas dataframe"

3

replace multiple values in pandas column

df = pd.DataFrame({'a':['Small', 'Medium', 'High']})

In [22]: df
Out[22]: 
        a
0   Small
1  Medium
2    High

[3 rows x 1 columns]

df.replace({'a' : { 'Medium' : 2, 'Small' : 1, 'High' : 3 }})
Posted by: Guest on October-05-2020
0

update multiple rows dataframe

df.loc[df.strings.isin(["C", "D", "E"]), df.columns.difference(["strings"])] = 0
df
Out[82]: 
  price strings value
0     1       A     a
1     2       B     b
2     0       C     0
3     0       D     0
4     0       E     0
Posted by: Guest on June-19-2021

Code answers related to "change multiple values in an element pandas dataframe"

Python Answers by Framework

Browse Popular Code Answers by Language