1

I have dataframe like this sample.

priceUsd,time,date
38492.2698958105979245,1627948800000,2021-08-03T00:00:00.000Z
39573.1543437718690816,1628035200000,2021-08-04T00:00:00.000Z
40090.5174131427618446,1628121600000,2021-08-05T00:00:00.000Z
41356.0360622010701055,1628208000000,2021-08-06T00:00:00.000Z
43535.9969201307711635,1628294400000,2021-08-07T00:00:00.000Z

I want to split last 10 rows for test dataset in tensorflow and I get data from first row to before last 10 rows for train.

train = df.loc[:-10 , ['priceUsd']]
test = df.loc[-10: , ['priceUsd']]

when I run this code it show error

TypeError: cannot do slice indexing on DatetimeIndex with these indexers [-10] of type int

How to fix it?

1
  • You could use iloc, e.g. train = df.iloc[:-10 , 0]. Commented Sep 2, 2021 at 8:14

1 Answer 1

1

Try this instead:

train = df[['priceUsd']].head(len(df) - 10)
test = df[['priceUsd']].tail(10)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.