Sometimes I want to use all columns and sometimes I want to exclude the last column.
df.iloc[:, :].apply(foobar) # all columns
df.iloc[:, :-1].apply(foobar) # exclude last column
Can I parameterize that somehow?
if exclude_last:
idx = ':-1'
else:
idx = ':'
df.iloc[:, idx].apply(foobar)
>Solution :
You can use df.columns for this purpose:
if exclude_last:
cols = df.columns[:-1]
else:
cols = df.columns
df.loc[:, cols].apply(foobar)