0

I understand this is a repeat question, but I can't find a succinct answer (or as a newbie, I can't succinctly understand an answer).

I have 2 sets of lists that I want to reference (separately) within a function:

cols = ['snow','ice']
metrics ['feet','inches']
def avg(df):

df1 = df.groupby(cols[0], as_index=False)[metrics[0]].mean()
    .sort_values(metrics[0]).drop_duplicates()

   return df1

avg(df)

This runs properly. How can I add an additional metric index (and if not, why not and what's the best approach)? Like this:

def avg(df):

df1 = df.groupby(cols[0], as_index=False)[metrics[0,1]].mean()
    .sort_values(metrics[0]).drop_duplicates()

   return df1

avg(df)

Thank you

paranormaldist
  • 489
  • 5
  • 16

1 Answers1

0

That's not possible, but you can access to both values using:

metrics[0:2]

If you don't know about that, please check about slices in python. These answers may help you: Slices in python

Edgar Magallon
  • 556
  • 2
  • 7
  • 15
  • i see thank you for the answer and reference material as well :) – paranormaldist Feb 01 '21 at 16:15
  • My recommendation is that you read a book about python, I'm reading Fluent Python book by Luciano Ramalho and it's very good. I also recommend you watch videos on youtube or any course about python. – Edgar Magallon Feb 01 '21 at 16:26