Instagram
youtube
Facebook
Twitter

Element-wise Function Application in Pandas

A Element-wise Function Application in Pandas?

Code Explanation:
● Library Import: pandas is imported as pd.

● DataFrame Creation: A DataFrame df is created with two columns, 'A' and 'B'.

● Element-wise Function: applymap applies the lambda function x * 2 to each element.

● Store Result: The result is stored in new_df.

● Output Display: print(new_df) shows the new DataFrame with doubled values.

 

Program:
 

import pandas as pd

df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
new_df = df.applymap(lambda x: x * 2)
print(new_df)