Answers for "replace multiple columns for a type pandas"

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
2

pandas change multiple column types

#Method 1:
df["Delivery Charges"] = df[["Weight", "Package Size", "Delivery Mode"]].apply(
  lambda x : calculate_rate(*x), axis=1)

#Method 2:
df["Delivery Charges"] = df.apply(
  lambda x : calculate_rate(x["Weight"], 
  x["Package Size"], x["Delivery Mode"]), axis=1)
Posted by: Guest on May-14-2021

Code answers related to "replace multiple columns for a type pandas"

Python Answers by Framework

Browse Popular Code Answers by Language