It looks like you're using an Ad Blocker.

Please white-list or disable AboveTopSecret.com in your ad-blocking tool.

Thank you.

 

Some features of ATS will be disabled while you continue to use an ad-blocker.

 

Data Analysis with Python: Calculating Mean and Median

page: 1
1

log in

join
share:

posted on Oct, 3 2023 @ 06:30 AM
link   
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!



posted on Oct, 3 2023 @ 11:06 AM
link   
Just re-registered after losing my account years ago and lurking since.

Can't you easily use the statistics library in python to do this? (It has been a while since I played with python as I mainly used it to write small tools and things in Blender about five years ago.)

www.w3schools.com...

-JS



posted on Oct, 3 2023 @ 01:49 PM
link   
a reply to: Mobo01

One aspect of AI that has impressed me is its ability to churn out code. DeepAI responded to your question with,



To calculate the mean and median of the list of numbers in Python, you can use the following code:

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

# Calculate the mean
mean = sum(data) / len(data)

# Calculate the median
sorted_data = sorted(data)
if len(data) % 2 == 0:
median = (sorted_data[len(data)//2 - 1] + sorted_data[len(data)//2]) / 2
else:
median = sorted_data[len(data)//2]

print("Mean:", mean)
print("Median:", median)
```

This will output:

```
Mean: 43.55555555555556
Median: 41
```


FWIW.

ETA-- when I calc the mean on a hand calculator, it is not the same value as output by DeepAI. Would suggest running this code on various data sets that you can hand check.

Cheers
edit on 3-10-2023 by F2d5thCavv2 because: (no reason given)



posted on Oct, 3 2023 @ 05:04 PM
link   
Forgot we have a limited time to edit a post... Anyhow here is the code.

import statistics as s
data = [12, 45, 67, 23, 41, 89, 34, 54, 21]

print(s.mean(data))
print(s.median(data))



posted on Oct, 4 2023 @ 02:29 PM
link   
a reply to: F2d5thCavv2

Yeah, was going to say the same. If it is for a class assignment maybe Ai would not be allowed.




top topics
 
1

log in

join