473,416 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Beginner - Python code working for sample data only

Hi everyone,

I'm new to Python. My manager wants me to run a Python code and generate output for 40 set of values. The code works fine for sample data. But when I replace it with actual data, it doesn't give me any output.

Below is the code. Sample data is given in the code as data = [.., .., ..]. One set of actual data for which I would like to generate output is data = [10.7369, 10.9114, 10.2428, 10.4129, 10.6323, 10.3315, 11.213, 10.405, 10.1623, 10.4183, 10.463, 10.1772, 10.967, 10.9385, 10.4935, 10.3695, 10.708, 11.0088].

It would be a great help if anyone could help me with this. Thanks very much.

Expand|Select|Wrap|Line Numbers
  1. import numpy as np
  2. from scipy.stats import norm
  3.  
  4. def mann_kendall_test(data, alpha=0.05):
  5.     """
  6.     Perform the Mann-Kendall test to detect trends and change points in a time series dataset.
  7.     Returns a tuple containing the test statistic, p-value, and a list of change point indices.
  8.     """
  9.     n = len(data)
  10.     s = 0
  11.     for i in range(n-1):
  12.         for j in range(i+1, n):
  13.             s += np.sign(data[j] - data[i])
  14.     var_s = n*(n-1)*(2*n+5)/18
  15.     if s > 0:
  16.         z = (s - 1) / np.sqrt(var_s)
  17.     elif s < 0:
  18.         z = (s + 1) / np.sqrt(var_s)
  19.     else:
  20.         z = 0
  21.     p = 2 * (1 - norm.cdf(np.abs(z)))
  22.     change_points = []
  23.     if p < alpha:
  24.         for i in range(1, n):
  25.             if np.sign(data[i] - data[i-1]) != np.sign(s):
  26.                 change_points.append(i-1)
  27.     return s, p, change_points
  28.  
  29. data = [10, 11, 13, 12, 15, 18, 16, 19, 20, 22, 24, 25, 27, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
  30. s, p, change_points = mann_kendall_test(data)
  31. print(f"Test statistic: {s}")
  32. print(f"P-value: {p}")
  33. print(f"Change points: {change_points}")
  34.  
  35.  
Apr 5 '23 #1
0 1171

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Aurélien Géron | last post by:
Hi, Does anyone know where I can find a lot of Python code snippets? I searched the Python wiki and Internet but could not find more than five or ten code snippets at a time. I'm looking...
4
by: Andreas Neudecker | last post by:
Hi. I have seen some discussions going on about making Python code faster and several measures looked fairly 'esoteric' to me (i.e.: you need to know a lot of background things to even KNOW...
0
by: Chris McKeever | last post by:
I am trying to modify the Mailman Python code to stop mapping MIME-types and use the extension of the attachment instead. I am pretty much clueless as to what I need to do here, but I think I have...
4
by: Tim Morrison | last post by:
SQL Server 2000 Is there any way to take sample data in my database and create an INSERT INTO script? I have a commercial application that I would like to include sample data, and instead of...
0
by: kiran kumar | last post by:
Hi All, I am working on embedded python on C these days. I feel there is a memory leakage in this code. I have used our own memory pool and all the python code will use the heap from this memory...
23
by: Python Maniac | last post by:
I am new to Python however I would like some feedback from those who know more about Python than I do at this time. def scrambleLine(line): s = '' for c in line: s += chr(ord(c) | 0x80)...
6
by: Dave067 | last post by:
Hi This is my first attempt at writing Python script - it's probably a bit ambitious, but there again, whatever doesn't kill you makes you stronger... ;-) I'm trying to write a script for a...
2
by: Van Lee | last post by:
PLEASE HELP!!! I am trying to refresh the data part only in my web page so that the pictures and the borders all stay. The refresh rate will need to be every 5 seconds so you can see that...
2
by: Fatman003 | last post by:
I have to copy data from 6 workbooks and paste it into a master workbook. All the workbooks are located in a folder on my desktop: C:\Users\f6565\Desktop\data The workbooks contain a sheet named...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.