I have a list of Timestamp
called dates_list, which I want to use to extract values from another data frame df. However,
df.loc[dates_list,:]
>>ValueError: mixed datetimes and integers in passed array
dates_list
looks like:
dates_list
>>[Timestamp('2000-06-02 00:00:00'),
Timestamp('2010-06-13 00:00:00'),
Timestamp('1997-06-26 00:00:00'),
Timestamp('2014-06-03 00:00:00'),
Timestamp('2007-06-14 00:00:00'),
Timestamp('1982-06-06 00:00:00'),
Timestamp('1998-06-21 00:00:00'),
Timestamp('2006-07-15 00:00:00'),
....]
df.index[1]
>>Timestamp('1979-01-01 00:00:00')
df.info()
>><class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 164880 entries, 1979-01-01 to 2017-02-01
Data columns (total 2 columns):
longitude 164880 non-null float64
Var1 164880 non-null float64
dtypes: float64(2)
memory usage: 8.8 MB
I also tried converting my dates_list
to datetime
using
dates_list2 = pd.to_datetime(dates_list)
But still, I see the same error. However, using just one item of the list flags another KeyError
dates_list2[1]
>>Timestamp('2010-06-13 00:00:00')
df.loc[dates_list2[1], : ]
>>KeyError: 1276387200000000000
This question also has a similar problem but doesn't have a solution. And this also gets the same ValueError
but it's performing a different operation all together.