I have a DataFrame full of floats (positive and negative) and some NaN. I\'d like to replace every single float number with its sign:
if it\'s NaN -> it remai
Code -
import pandas as pd df = pd.DataFrame({'x' : [-5.3, 2.5, 0, float('nan')]}) df['x'] = df['x'].apply(func = lambda x : x if not x else x // abs(x)) print(df)
Output -
x 0 -1 1 1 2 0 3 NaN