1

I do not understand the difference between the following code:

import pandas as pd

frame = pd.DataFrame([[1,2,3],[1,5,6],[7,8,9]])
frame2 = frame.loc[[0,1]]
frame2.loc[1,1] = -99

and

frame = pd.DataFrame([[1,2,3],[1,5,6],[7,8,9]])
frame2 = frame.loc[:2]
frame2.loc[1,1] = -99

Why referencing via integer list does not change the original variable "frame" in contrast to referencing via integer slicing?

  • `frame.loc[[0,1]]` will match the labels `0` and `1` in the index whereas `frame.loc[:2]` slices `0` up untill `2` – anky Jun 28 '19 at 11:37

0 Answers0