0

I'm working with a big dataset and when I'm performing this function:

data1['total_t_1'] = data1.groupby(level=0)['total_tax'].apply(lambda x: x.shift())

I'm getting this error: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc [row_indexer, col_indexer] = value instead.

I recognize that the error is on this part: apply(lambda x: x.shift())

Can somebody would advice me what to do to avoid this issue?

PAstudilloE
  • 659
  • 13
  • 24

1 Answers1

1

It's just warning you that data1 came from a slice of another DataFrame, and that you therefore shouldn't expect the original DataFrame to be updated when you change data1. If you want to make the warning go away then set data1 = data1.copy() first. See the link from pault's comment (How to deal with SettingWithCopyWarning in Pandas?) for further information.

PAG
  • 1,836
  • 1
  • 18
  • 19