How to drop rows containing NaN values in a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/remove-ro...
Python code of this video:
import pandas as pd # Load pandas
data = pd.DataFrame( # Create DataFrame with NaN values
{"x1":[1, 2, float("NaN"), 4, 5, 6],
"x2":["a", "b", float("NaN"), float("NaN"), "e", "f"],
"x3":[float("NaN"), 10, float("NaN"), float("NaN"), 12, 13]})
print(data) # Print DataFrame with NaN values
data1 = data.dropna() # Apply dropna() function
print(data1) # Print updated DataFrame
data2a = data.dropna(subset = ["x2"]) # Apply dropna() function
print(data2a) # Print updated DataFrame
data2b = data[data["x2"].notna()] # Apply notna() function
print(data2b) # Print updated DataFrame
data2c = data[pd.notnull(data["x2"])] # Apply notnull() function
print(data2c) # Print updated DataFrame
data3a = data.dropna(how = "all") # Apply dropna() function
print(data3a) # Print updated DataFrame
data3b = data[data.notna().any(axis = 1)] # Apply notna() function
print(data3b) # Print updated DataFrame
data3c = data[data.notnull().any(axis = 1)] # Apply notnull() function
print(data3c) # Print updated DataFrame
data4 = data.dropna(thresh = 2) # Apply dropna() function
print(data4) # Print updated DataFrame
Follow me on Social Media:
Facebook – Statistics Globe Page: / statisticsglobecom
Facebook – R Programming Group for Discussions & Questions: / statisticsglobe
Facebook – Python Programming Group for Discussions & Questions: / statisticsglobepython
LinkedIn – Statistics Globe Page: / statisticsglobe
LinkedIn – R Programming Group for Discussions & Questions: / 12555223
LinkedIn – Python Programming Group for Discussions & Questions: / 12673534
Twitter: / joachimschork
Music by bensound.com
On this page of the site you can watch the video online Remove Rows with NaN from pandas DataFrame in Python (Example) | How to Drop & Delete Missing Data with a duration of hours minute second in good quality, which was uploaded by the user Statistics Globe 27 March 2023, share the link with friends and acquaintances, this video has already been watched 2,034 times on youtube and it was liked by 27 viewers. Enjoy your viewing!