Source Code:
(back to article)
import pandas as pd # Create a sample DataFrame df = pd.DataFrame({'A': [1, 2, 3, 4, float('nan')], 'B': [float('nan'), float('nan'), 5, 6, 7]}) # Count the number of NaN values in column 'A' nan_count_a = df['A'].isna().sum() # Count the number of NaN values in column 'B' nan_count_b = df['B'].isna().sum() print(nan_count_a) #1 print(nan_count_b) #2
Result:
Report an issue