Venugopal Bukkala
Venugopal Bukkala

Reputation: 179

Plot the graph excluding missing values in pandas or matplotlib

I am new to time-series programming with Pandas. Here is the sample data:

                     date       2      3      4  ShiftedPrice
0 2017-11-05 09:20:01.134  2123.0  12.23  34.12         300.0
1 2017-11-05 09:20:01.789  2133.0  32.43  45.62         330.0
2 2017-11-05 09:20:02.238  2423.0  35.43  55.62           NaN
3 2017-11-05 09:20:02.567  3423.0  65.43  56.62           NaN
4 2017-11-05 09:20:02.948  2463.0  45.43  58.62           NaN

I would like to plot date vs ShiftedPrice for all pairs where there is no missing values for ShiftedPrice column. You can assume that there will absolutely be no missing values in data column. So please do help me in this.

Upvotes: 2

Views: 6581

Answers (1)

jezrael
jezrael

Reputation: 862431

You can first remove NaNs rows by dropna:

df = df.dropna(subset=['ShiftedPrice'])

And then plot:

df.plot(x='date', y='ShiftedPrice')

All together:

df.dropna(subset=['ShiftedPrice']).plot(x='date', y='ShiftedPrice')

Upvotes: 3

Related Questions