0

I'm trying to run a code which was written a while ago and the problem is they used pandas.dataframe.ix which apparently no longer exists (I have the version 1.2.4) So I'm trying to make it work using iloc and loc but there are parts where it refers to dates and I don't know what I could do as it's neither a label nor an integer

Here is an example of my problem:

def ExtractPeriode(self, dtStartPeriode, dtEndPeriode):

start=self.Energie.index.searchsorted(dtStartPeriode)

end=self.Energie.index.searchsorted(dtEndPeriode)

self.Energie = self.Energie.ix[start:end]

Does someone know what I could use to replace .ix in this situation? Also you might have noticed I'm not very experienced with coding so please try to keep your answers simple if you can

Caroline
  • 3
  • 1

1 Answers1

1

.loc is used for any label, so if you have dates as your index, you can pass in the date. But .searchsorted returns an integer - the row number where you should insert, so you should use .iloc.

self.Energie = self.Energie.iloc[start:end]
Safwan Samsudeen
  • 1,645
  • 1
  • 10
  • 25
  • Alternatively, you can install an older version of Pandas, check this [SO post](https://stackoverflow.com/questions/50231134/how-to-downgrade-pandas-version) – Safwan Samsudeen May 28 '21 at 09:28