Source Code:
(back to article)
import pandas as pd # Create a sample dataframe df = pd.DataFrame({'A': [1, 2, 3, 4, 5, float('nan')], 'B': [6, 7, 8, 9, float('nan'), 11], 'C': [12, 13, 14, 15, 16, 17]}) # Replace NaN values in column 'A' with 0 df['A'] = df['A'].fillna(0) print(df)
Result:
Report an issue