Jump to content

Data Analysis with Python: Calculating Mean and Median

Featured Replies

I'm working on a data analysis project in Python and need to calculate both the mean and median of a dataset. I understand the basic concepts, but I'm looking for a Python code example that demonstrates how to do this efficiently.

Let's say I have a list of numbers:

data = [12, 45, 67, 23, 41, 89, 34, 54, 21]

I want to calculate both the mean and median of these numbers. Could you provide a Python code snippet that accomplishes this? Additionally, it would be helpful if you could explain any libraries or functions used in the code.

Thank you for your assistance in calculating these basic statistics for my data analysis project!

28 minutes ago, WalidKhan said:

I'm working on..

No, you do not work..

 

32 minutes ago, WalidKhan said:

but I'm looking for a Python code example that demonstrates how to do this efficiently.

...then show your not optimal code....

 

  • 6 months later...

All of the data analysis stuff in Python begins with the numpy library. Use numpy.mean() and numpy.median() after casting your list to a numpy.array like so:

Data = numpy.array([1,2,3])

Honestly the best advice though is use chatGPT for little coding questions like this.

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.