- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove NaN values from a dataframe without fillna or Interpolate (Python Matplotlib)
To remove NaN values from a dataframe without filter or interpolate, we can take the following steps −
Steps
Set the figure size and adjust the padding between and around the subplots.
Create an array to make a Pandas data frame.
One-dimensional ndarray with axis labels (including time series).
Plotting interpolation, 'index', 'values' − Use the actual numerical values of the index.
To display the figure, use show() method.
Example
import numpy as np import pandas as pd from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Numpy array data = np.array([1., 1.2, 0.89, np.NAN, 1.2, np.NAN, 1.89, 2.09, .78, .67, np.NAN, 1.78, np.NAN, 1.56, 1.89, 2.78] ) # Pandas dataframe df = pd.Series(data) # Plot the interpolation df.interpolate('index').plot(marker='o') # Display the plot plt.show()
Output
It will produce the following output −
- Related Articles
- Python - Remove the missing (NaN) values in the DataFrame
- Python - Remove duplicate values from a Pandas DataFrame
- Drop rows from Pandas dataframe with missing values or NaN in columns
- Python Pandas - Return Index without NaN values
- How to count the NaN values in a column in a Python Pandas DataFrame?
- How to replace NaN values of a series with the mean of elements using the fillna() method?
- Merge Python Pandas dataframe with a common column and set NaN for unmatched values
- How to deal with NaN values while plotting a boxplot using Python Matplotlib?
- How to interpolate data values into strings in Python?
- How to remove a frame without removing the axes tick labels from a Matplotlib figure in Python?
- How to remove NaN from a Pandas Series?
- Python Pandas – Remove numbers from string in a DataFrame column
- Python – Display only non-duplicate values from a DataFrame
- Create a Pipeline and remove a column from DataFrame - Python Pandas
- How to plot masked and NaN values in Matplotlib?

Advertisements