This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
In this article, you will learn how to drop rows with missing values in Python.
Let’s say you have a DataFrame of food with two columns, “Name” and “Price ($)”. One of the data in column “Price ($)” is missing and therefore labelled as pd.NaT. In the pandas
module, NaT is used to represent missing values.
# Import pandas module
import pandas as pd
df = pd.DataFrame({"Name": ['Pizza', 'Burger', 'Waffle'],
"Price ($)": [10, pd.NaT, 6]})
In order to drop rows with missing values, you can use the DataFrame.dropna()
method.
# Import pandas module
import pandas as pd
df = pd.DataFrame({"Name": ['Pizza', 'Burger', 'Waffle'],
"Price ($)": [10, pd.NaT, 6]})
print(df.dropna())
Note: The DataFrame.dropna()
method functions by dropping rows with missing values by default.
The post How to Drop Rows With Missing Values in Python appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Ariessa Norramli

Ariessa Norramli | Sciencx (2021-02-24T10:19:55+00:00) How to Drop Rows With Missing Values in Python. Retrieved from https://www.scien.cx/2021/02/24/how-to-drop-rows-with-missing-values-in-python/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.