Hello, I've been stumped for several weeks on this particlar program. At work here, we have 30 machines that we record scrap data on. I take this data and create spreadsheets (boring) that can be used for analysis. Anyway, I was wondering how I could change this "for" statement to a much more condensed amount of code. -
for i in range(30):
-
while hold[n,3] == 1:
-
hold_01.append( hold[n,8] )
-
hDate_01.append( hold[n,0] )
-
n = n + 1
-
while hold[n,3] == 2:
-
hold_02.append( hold[n,8] )
-
hDate_02.append( hold[n,0] )
-
n = n + 1
-
while hold[n,3] == 3:
... and so on, for a total of 30 machines.
Is there anyway to alter the line(s) with the .append from a 1-D vector to a 2-D array, so I can set me while loop == i, and add the data from hold[] to the next row, and so on. Any help would be greatly appreciated.
Thanks,
~~archeryguru2000~~
3 2121 bvdet 2,851
Expert Mod 2GB
Hello, I've been stumped for several weeks on this particlar program. At work here, we have 30 machines that we record scrap data on. I take this data and create spreadsheets (boring) that can be used for analysis. Anyway, I was wondering how I could change this "for" statement to a much more condensed amount of code.
for i in range(30):
while hold[n,3] == 1:
hold_01.append( hold[n,8] )
hDate_01.append( hold[n,0] )
n = n + 1
while hold[n,3] == 2:
hold_02.append( hold[n,8] )
hDate_02.append( hold[n,0] )
n = n + 1
while hold[n,3] == 3:
... and so on, for a total of 30 machines.
Is there anyway to alter the line(s) with the .append from a 1-D vector to a 2-D array, so I can set me while loop == i, and add the data from hold[] to the next row, and so on. Any help would be greatly appreciated.
Thanks,
~~archeryguru2000~~
Please use code tags around your code. Can you show us the structure of your original data and the output you are trying to achieve?
Maybe you are looking for something like this: - dataDict = dict.fromkeys(['hold_%02d' % i for i in range(1,31)], [])
-
keys = dataDict.keys()
-
keys.sort()
-
for i, key in enumerate(keys):
-
dataDict[key] = [hold[i,8], hold[i,0]]
From the dictionary you can write a 2D CSV file for your spreadsheet.
Please use code tags around your code. Can you show us the structure of your original data and the output you are trying to achieve?
Maybe you are looking for something like this: - dataDict = dict.fromkeys(['hold_%02d' % i for i in range(1,31)], [])
-
keys = dataDict.keys()
-
keys.sort()
-
for i, key in enumerate(keys):
-
dataDict[key] = [hold[i,8], hold[i,0]]
From the dictionary you can write a 2D CSV file for your spreadsheet.
I alway like your dictionary solutions. I was going to say: put lists into a list: - hold_01 = ['a', 'list', 'of', 'stuff']
-
hold_02 = ['another', 'list', 'of', 'stuff']
-
-
holdList = [eval('hold_%02d' %i) for i in range(1, 3)]
-
print holdList
-
Then in the while loop it's: - holdList[i].append( hold[n,8] )
I alway like your dictionary solutions. I was going to say: put lists into a list: - hold_01 = ['a', 'list', 'of', 'stuff']
-
hold_02 = ['another', 'list', 'of', 'stuff']
-
-
holdList = [eval('hold_%02d' %i) for i in range(1, 3)]
-
print holdList
-
Then in the while loop it's: - holdList[i].append( hold[n,8] )
Of course, if all you need is a 2D empty list, the syntax would be: - holdList = [[] for i in range(30)]
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sybren Stuvel |
last post by:
Hi there,
Is it possible to use an assignment in a while-loop? I'd like to do
something like "loop while there is still something to be read, and if
there is, put it in this variable". I've been...
|
by: Invalid User |
last post by:
While trying to print a none empty list, I accidentaly put an "else"
statement with a "for" instead of "if". Here is what I had:
if ( len(mylist)> 0) :
for x,y in mylist:
print x,y
else:...
|
by: Toby Newman |
last post by:
At the page:
http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000
or
http://tinyurl.com/4ptzs
the author warns:
"The for loop is frequently used, usually...
|
by: John Pass |
last post by:
What is the difference between a While and Do While/Loop repetition structure.
If they is no difference (as it seems) why do both exist?
|
by: Fabian Vilers |
last post by:
Hi again...
I'm wondering what could be better in terms of performance between:
var my_array = new Array();
// populate array
for (index in my_array)
{
// do something with my_array
|
by: morpheus |
last post by:
Hi Group,
When I run this:
# include <stdio.h>
int main(){
int c=0;
while ( (c=getchar()) != EOF && c != ' ' && c != '\t' )
printf("foo");
if (c == '8')
putchar(c);
|
by: Frederick Gotham |
last post by:
Is the domestic usage of the C "for" loop inefficient when it comes to
simple incrementation? Here's a very simple program that prints out the
bit-numbers in a byte.
#include <stdio.h>
#include...
|
by: Wazza |
last post by:
G'Day,
I have a re-occurring problem and wish to design a framework or
pattern to address it. I have some Ideas but I would like to do some
brainstorming with my peers before commencing.
The...
|
by: Kerem Gümrükcü |
last post by:
Hi All,
i am too tired now to find this out by my own, but why does
my while loop "while(readline==Console.ReadLine())" needs
twice return hit to read the line, after setting...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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: 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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |