473,395 Members | 1,738 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,395 software developers and data experts.

How to create an algorithm to evaluate a string?

Hello All!
I am using mysql and python together. I have a table with only two columns: Number and Price. It looks something like this:
Number, Price
1, 10
2, 13
3, 19
4, 12
etc.

This continues for 90 rows until the Number values restart at 1, however the Price values keep changing. In all there are 900 rows.
What I would like to do is take the Price at all Number 2 and subtract that from the Price at Number 5. Then take the Price at Number 4 and subtract that from the Price at Number 5. If both of these numbers are positive or both are negative, I would like to store that number and move onto the next set of 90 Numbers. If They are both not positive or both not negative, then I would like to move on to the Price at number 5 subtract that from the Price at Number 6, Now check if this number has the same sign as the difference between Number 2 and Number 6.
So in all there should be a string of 10 values, one from each set of 90 numbers.
Any help at all will be greatly appreciated!
Thank you,
Ron Parker
Jan 11 '11 #1
1 1823
Sorry, I did not include a starting point. Also, I apologize if my values look a little funny. However, I thought something like this to begin. As you can see, I am not very good at this though. So again, help me please!
Ron Parker

Expand|Select|Wrap|Line Numbers
  1. >>> Price = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
  2. >>> def Best(seq):
  3. ...     first seq(5)-seq(2)
  4.         second seq(5)-seq(4)
  5.         if first/numpy.abs(first)=second/numpy.abs(second)
  6.               return second
  7.         else
  8.             seq(5+1)-seq(2+1)
  9.  
  10. ... 
  11. >>> [best(data[i:i+90]) for i in range(0, len(data), 90)]
  12.  
  13.  
  14.  
  15.  
Jan 11 '11 #2

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

Similar topics

2
by: J. van Herten | last post by:
I am searching for the replacement of the scriptcontrol of VB6 in .NET. I am plaing with the CodeDOM but I cannot get to evaluate a string text to the result I want. String text = "1 + 2"...
13
by: M | last post by:
Hi, I've searched through the previous posts and there seems to be a few examples of search and replacing all occurrances of a string with another string. I would have thought that the code...
8
by: VM | last post by:
I'm trying to find out what the best way would be to parse a formula so I can then calculate it with its real values. For example, a user may enter ((sys_empHours*db_empSal)/db_totalHours) and I...
2
by: Kamal Ahmed | last post by:
Hi all, I want to execute a String that is generated at Runtime and fills data in DropDownList Controls at Runtime. I want to do this at server side. As Eval functions works as client side...
8
by: No Such Luck | last post by:
Is there anyway to literally evaluate the contents of a string in an if statement? For example: int i = 0; char * str = "i == 0"; if(str) /* I know this doesn't do what I want */ {
4
by: netnet | last post by:
Is it possible to evaluate a string as a method name? Something like this: Session = "loadFormFormACompany"; This is what I would like to do.... eval(Session+"()") Anyone have any ideas?
6
by: peace2007 | last post by:
Hi, I need to evaluate the return result of a function from Server.aspx as following. But it doesn't work as I need function getAjax() { var XmlHttp; //Creating object of XMLHTTP...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.