To me, it seems df.take() has the same functionality as the more common df.iloc[]. I've checked the documentation but couldn't find a difference. Are there cases where take() is preferable to iloc[]?
To me, it seems df.take() has the same functionality as the more common df.iloc[]. I've checked the documentation but couldn't find a difference. Are there cases where take() is preferable to iloc[]?
There are some pretty important differences:
Case: I received the following error message and finally figured out that it was hanging up on the .iloc.
TypeError: unhashable type: 'list'
Since the iloc returned a list which is mutable, the code wouldn't proceed with the summation. A simple change from .iloc to .take fixed the problem.
#returns list
df3['sum_total']= df3.iloc[:,-30].sum(axis=[1])
#returns tuple and worked
df3['sum_total']= df3.take([-30], axis=1).sum(axis=1)