Tian He
Tian He

Reputation: 372

Better ways to organize data

So I have the following loop:

for temperature in [-40,25,85]:
    for voltage in [24, 28, 32]:
        for power in [50,100,200]:
            #measurement 1
            ...
            #measurement 2
            ...   

There is a question of how to organize the measured data. Up to now I've been creating a separate folder at each loop for each loop variable, so if I want to grab the data for measurement 1 at -40°C, 28V and 100W, I'll just go to ./-40/28/100. It's been working reasonably well but I cannot help wondering whether there is a better way.

Upvotes: 1

Views: 1045

Answers (2)

Tian He
Tian He

Reputation: 372

I've found that the pandas module serves my purpose well. By using it I can save all controlling variables and measurement results in one table, which later on can be easily accessible for all kinds of slicing, grouping and plotting.

Upvotes: 1

tmj
tmj

Reputation: 1858

import json

dictionary = {}

for temperature in [-40,25,85]:
    for voltage in [24, 28, 32]:
        for power in [50,100,200]:
            #measurement 1
            #measurement 2..
            dictionary[str((temperature,voltage,power))] = (measurement1,measurement2,...)

f = open(".../somefile.txt",'w')
f.write(json.dumps(dictionary,indent=1,sort_keys=True))
f.close()

Maybe JSON can help you.

Upvotes: 3

Related Questions