-1

that is my date I want to choose

myDates=['2021-02-24', '2021-02-26','2021-02-27', '2021-03-06', '2021-04-4', '2021-04-05', '2021-04-06',
         '2021-04-07', '2021-04-08','2021-04-13', '2021-04-14', '2021-04-15', '2021-04-16','2021-04-17',
         '2021-04-22','2021-04-23', '2021-04-28', '2021-04-29', '2021-04-30', '2021-05-02', '2021-05-03',
         '2021-05-04' ,'2021-05-05', '2021-05-06', '2021-05-08']

change them to date time

myDates=pd.to_datetime(myDates)

and trying to use .loc function

df1=df.loc[myDates]

I get that message

'Passing list-likes to .loc or [] with any missing labels is no longer supported, see https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike'

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57

1 Answers1

0

in regards to your issue, you're trying to apply a pandas operation on a list, that won't work. you first need to create a pandas object.

use a boolean filter in a dataframe and diff()

assuming your dataframe looks like this :

myDates=['2021-02-24', '2021-02-26','2021-02-27', '2021-03-06', '2021-04-4', '2021-04-05', '2021-04-06', '2021-04-07', '2021-04-08','2021-04-13', '2021-04-14', '2021-04-15', '2021-04-16','2021-04-17', '2021-04-22','2021-04-23', '2021-04-28', '2021-04-29', '2021-04-30', '2021-05-02', '2021-05-03', '2021-05-04' ,'2021-05-05', '2021-05-06', '2021-05-08']

myDates=pd.to_datetime(myDates)

df = pd.DataFrame(myDates)
print(df.head(5))
          0
0 2021-02-24
1 2021-02-26
2 2021-02-27
3 2021-03-06
4 2021-04-04

df[df[0].diff().gt('1 days')]

  0
1  2021-02-26
3  2021-03-06
4  2021-04-04
9  2021-04-13
14 2021-04-22
16 2021-04-28
19 2021-05-02
24 2021-05-08

print(df.assign(diff=df[0].diff()))

            0    diff
0  2021-02-24     NaT
1  2021-02-26  2 days
2  2021-02-27  1 days
3  2021-03-06  7 days
4  2021-04-04 29 days
5  2021-04-05  1 days
6  2021-04-06  1 days
7  2021-04-07  1 days
8  2021-04-08  1 days
9  2021-04-13  5 days
10 2021-04-14  1 days
11 2021-04-15  1 days
12 2021-04-16  1 days
13 2021-04-17  1 days
14 2021-04-22  5 days
15 2021-04-23  1 days
16 2021-04-28  5 days
17 2021-04-29  1 days
18 2021-04-30  1 days
19 2021-05-02  2 days
20 2021-05-03  1 days
21 2021-05-04  1 days
22 2021-05-05  1 days
23 2021-05-06  1 days
24 2021-05-08  2 days
Umar.H
  • 22,559
  • 7
  • 39
  • 74
  • firs of all thank you for your responses . but what i want to do is to choose that specific dates (myDates) from the bigger df that contain the info i need. the bigger df have time index from 2021-02-24 to the 2021-05-10 so i want to separate that times to a new dataframe – Imri Zadak Jul 25 '21 at 10:41
  • @ImriZadak please see [mcve] and [ask] you need to provide a proper example. – Umar.H Jul 25 '21 at 10:50