-2

Generate a new column "avgdelay" from the existing columns Note - You are expected to make a new column "avgdelay" by grouping "name_customer" column with reapect to mean of the "Delay" column. This new column "avg_delay" is meant to store "customer_name" wise delay groupby('name_customer')['Delay'].mean(numeric_only=False) Display the new "avg_delay" column

Can Anyone guide me

molbdnilo
  • 64,751
  • 3
  • 43
  • 82
  • Welcome to [Stack Overflow.](https://stackoverflow.com/ "Stack Overflow") Please be aware this site can help solve specific, technical problems, not open-ended requests. Please edit your question to show what you have tried so far. See the [How To Ask a Good Question](https://stackoverflow.com/help/how-to-ask "How To Ask a Good Question") and ["How do I ask and answer homework questions?"](https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions "How do I ask and answer homework questions?") pages for details on how to best help us help you. – itprorh66 Feb 20 '22 at 21:14
  • [Try this might answer your question:](https://stackoverflow.com/questions/71183072/how-to-change-days-format-to-total-second-in-pandas-data-frame/71194211#71194211) – Glenn Ho Feb 21 '22 at 14:36

1 Answers1

0

Let df be your main data frame

avgdelay = df.groupby('name_customer')['Delay'].mean(numeric_only=False)

You need to add the "avg_delay" column with the maindata, mapped with "name_customer" column

Note - You need to use map function to map the avgdelay with respect to "name_customer" column

df['avg_delay'] = df['name_customer'].map(avgdelay)