-1
[this is tail of my DataFrame for around 1000 entries][1]

            Open    Close   High    Change  mx_profitable
Date
2018-06-06  263.00  270.15  271.4   7.15    8.40
2018-06-08  268.95  273.00  273.9   4.05    4.95
2018-06-11  273.30  274.00  278.4   0.70    5.10
2018-06-12  274.00  282.85  284.4   8.85    10.40

I have to sort out the entries of only certain dates, for example, 25th of every month.

ravi
  • 1
  • 1
  • Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Jun 13 '18 at 10:24

1 Answers1

0

I think need DatetimeIndex.day with boolean indexing:

df[df.index.day == 25]

Sample:

rng = pd.date_range('2017-04-03', periods=1000)
df = pd.DataFrame({'a': range(1000)}, index=rng)  
print (df.head())
            a
2017-04-03  0
2017-04-04  1
2017-04-05  2
2017-04-06  3
2017-04-07  4

df1 = df[df.index.day == 25]
print (df1.head())
              a
2017-04-25   22
2017-05-25   52
2017-06-25   83
2017-07-25  113
2017-08-25  144
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • I am importing data from a library which assigning index in formate of date having **dtype='object'**, instead of **dtype='datetime64[ns]'** that's why `DatetimeIndex.day` is not working...any solution which convert dtype into datetime from object – ravi Jun 13 '18 at 11:32
  • @ravi - Then use `df.index = pd.to_datetime(df.index)` before – jezrael Jun 13 '18 at 11:33