CodingKid
CodingKid

Reputation: 43

How to set conditions for plotting values from a 3rd column? Python/pandas

I have imported data with pandas into 3 columns: DayOfYear, Field, Distance.

DayOfYear Field Distance
1          50      100
2          55      200
3          60      300
4          65      400
5          70      500
6          75      600
7          80      700
...          

I want to plot Field against Distance but i want to do it for any range of the day of year that i choose. So instead of just plotting all the values of Distance and Field for all 365 days, I would like to plot them For say days 226-346. How should i go about this?

Upvotes: 1

Views: 85

Answers (1)

ansev
ansev

Reputation: 30920

Use Series.between to performance a boolean indexing with DataFrame.plot:

l1 = 226
l2 = 346
df[df['DayOfYear'].between(l1,l2)].set_index('Distance')['Field'].plot()

Example for l1 = 2, l2 = 6,

enter image description here

Upvotes: 1

Related Questions