2

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.

Engineero
  • 12,340
  • 5
  • 53
  • 75
Light_B
  • 1,660
  • 1
  • 14
  • 28
  • 1
    Can you provide code for building a sample dataframe that illustrates the problem? – Engineero May 10 '19 at 14:43
  • 1
    The error shows up after several steps of preprocessing and extracting the dates. I will try to reproduce it in a sample dataframe – Light_B May 10 '19 at 15:01
  • 2
    @Engineero Thanks for asking to reproduce the problem. This helped me to figure out that the error shows up because of the dates that are not being present in the df. I should have checked that before but certainly, the error message could be improved here. – Light_B May 10 '19 at 15:16

0 Answers0