1

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

pandas.pydata.org/pandas-docs/stable/reference/api/… , DataFrame.plot use the index of DataFrame in the x axis, so we need set distance like the` index`. please consider accept or upvote:)
you would need filter the datafraem by the hour with datetime series we have use s.dt.hour.between(3,4)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.