when using pandas.plot(), how to not interpolate missing values in python

To avoid interpolation of missing values when using pandas.plot(), you can set the interpolate parameter to False. By default, this parameter is set to True.

Here is an example code snippet that demonstrates how you can do this:

main.py
import pandas as pd
import matplotlib.pyplot as plt

# create a dataframe with missing values
df = pd.DataFrame({'A': [1, 2, 3, None, None, 6], 'B': [7, None, None, 10, 11, 12]})

# plot the dataframe without interpolation
df.plot(kind='line', interpolate=False)

# show the plot
plt.show()
291 chars
12 lines

In this example, the df.plot() method is used to create a line plot of the dataframe. The interpolate parameter is set to False to prevent pandas from interpolating missing values. The resulting plot will have gaps where the missing values are located.

related categories

gistlibby LogSnag