select rows where 1 column is not null pandas code example
Example: pandas return rows that don't have null
# Basic syntax:
# Remove rows that have missing entries in specific column:
df[~df['column'].isnull()]
# Where df['Age'].isnull() returns a Series of booleans that are true
# when 'column' has an empty row. The ~ negates the Series so that you
# obtain the rows of df the don't have empty values in 'column'
# Remove rows that have missing entries in any column:
df.dropna()
# Example usage:
import pandas as pd
# Create dataframe
df = pd.DataFrame({'Last_Name': ['Smith', None, 'Brown'],
'First_Name': ['John', 'Mike', 'Bill'],
'Age': [35, 45, None]})
print(df)
Last_Name First_Name Age
0 Smith John 35.0
1 None Mike 45.0
2 Brown Bill NaN
df[~df['Age'].isnull()] # Returns:
Last_Name First_Name Age
0 Smith John 35.0
1 None Mike 45.0
df.dropna() # Returns:
Last_Name First_Name Age
0 Smith John 35.0