0

I have the following pandas data frame:

import pandas as pd
timestamps = np.arange(1, 53)
quantities = np.arange(1, 53)
data = dict(quantities=quantities)
df = pd.DataFrame(data=data, columns=data.keys(), index=timestamps)
df.rename_axis('timestamps', inplace=True)

I'm trying to get change the data frame to different values:

timestamps_new = [1, 1, 1, 2, 2, 2]
df = df.loc[timestamps_new]

This works, but I get the following warning:

FutureWarning: Passing list-likes to .loc or [] with any missing label will raise
KeyError in the future, you can use .reindex() as an alternative.

Why does this happen? I also get a KeyError when I use:

df = df.loc[timestamps_new, 'index']

or

df = df.loc[timestamps_new, 'timestamps']

Thanks for any help understanding this.

ajrlewis
  • 2,968
  • 3
  • 33
  • 67

0 Answers0