Instagram
youtube
Facebook
Twitter

Apply Function and Replace Values in Pandas Column

Apply Function and Replace Values in Pandas Column
Code Explanation:
Function Application: The apply() method is used on column 'A' to add 5 to each element.
Replace Value: The updated values overwrite the original values in column 'A'.
Output Display: The modified DataFrame is printed, showing updated values in column 'A'.

 

Program:

import pandas as pd

df = pd.DataFrame({
    'A': [10, 20, 30],
    'B': [40, 50, 60]
})

df['A'] = df['A'].apply(lambda x: x + 5)
print(df)