0
average_sessions_per_device = visits.groupby(['device']).agg({'session_duration_minute': ['mean']}).reset_index()
average_sessions_per_device.columns = ['device','average_duration' ]

average_sessions_per_device['minimum_duration'] = visits.groupby(['device']).agg({'session_duration_minute': ['min']}).reset_index()


average_sessions_per_device['maximum_duration'] = visits.groupby(['device']).agg({'session_duration_minute': ['max']}).reset_index()

average_sessions_per_device

I have a dataset with a column device(mobile/desktop) and duration of each session(time in minutes) and I want to find average, maximum and minimum session duration by each device.

I am getting the error as:

ValueError: Wrong number of items passed 2, placement implies 1

How can I resolve it?

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
  • Please include a _small_ subset of your data as a __copyable__ piece of code that can be used for testing as well as your expected output for the __provided__ data. See [MRE - Minimal, Reproducible, Example](https://stackoverflow.com/help/minimal-reproducible-example), and [How to make good reproducible pandas examples](https://stackoverflow.com/q/20109391/15497888). – Henry Ecker May 25 '21 at 23:52

1 Answers1

0

Try using

visits.groupby('device').agg({'session_duration_minute': ['min','max']}).reset_index()
Shubham Periwal
  • 2,198
  • 2
  • 8
  • 26