Created
March 24, 2020 05:54
-
-
Save yohanesnuwara/07de55b8cc3939632107c54127b5d573 to your computer and use it in GitHub Desktop.
Check and remove NaN values in DataFrame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
# create dataframe from data | |
data = pd.DataFrame({"Column_1": numpy_1, "Column_2": numpy_2, "Column_3": numpy_3}) | |
# print original size of data before NaN values removal | |
print("Original size of data:", len(data), "rows") | |
# look up the number of rows with NaN data | |
print("How many data with NaN values?") | |
print(data.isnull().sum()) | |
# drop rows with missing values | |
data.dropna(inplace=True) | |
# after removal, the index will be not set from 0 | |
# re-index dataframe (in order, started from 0) | |
data = data.reset_index(drop=True) | |
print("NaN has successfully been deleted") | |
# see data after removal | |
data.head(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample result: