The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum
 Origin Forum
 Make the same table using Python cvs module

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Ollisteka Posted - 09/14/2017 : 12:54:49 AM
Origin Ver. and Service Release (Select Help-->About Origin): 8.0724
Operating System: Windows 7

So, I have some data, which can fit in a table like tat one:



But what should I write in Python script, so when I import .csv file it would look like this exact table?

Right now I have this structure:

{'bubble_sort': {'BEST': {'COMP': 999000, 'PERM': 0, 'TIME': 1072.061538696289},
             'RND': {'COMP': 999000,
                     'PERM': 249853,
                     'TIME': 1731.0991287231445},
             'WORST': {'COMP': 999000,
                       'PERM': 499500,
                       'TIME': 2358.1347465515137}},
'hoare_sort': {'BEST': {'COMP': 10975, 'PERM': 0, 'TIME': 14.000654220581055},  #and so on


And this code to save it:

def write_csv_in_file(fn, data):
with open(fn + ".cvs", 'w') as file:
    writer = csv.writer(file)
    for key, value in data.items():
        writer.writerow([key, value])

And after importing get this table:

And it is far away from the variant I need.
3   L A T E S T    R E P L I E S    (Newest First)
ZanHUNG Posted - 09/14/2017 : 05:01:05 AM
quote:
Originally posted by Ollisteka

quote:


Please be more specific about the relationship between the table and the Python dictionary.

None of the values in the table is from the dictionary provided.

For example,

1) Elements' number [100,200,300,400] is not from the Python dictionary provided.
2) Bubble Time [10, 15, 20, 30] is not from the Python dictionary provided.





Well, values in the table are absolutely random right now. But let's say that this data was collected on best case array of length 100. Then for 1st row there should be values from ['bubble_sort']['BEST']['TIME'], ['hoare_sort']['BEST']['TIME'] and so on. Then I'd make the same tables for worst case scenario (["WORST"]), random (["RND"]), and then repeat everything for number of comparissons (["COMP"]) and permutations done (["PERM"])



'...the table are absolutely random...' - NO. Should have provided a real case to avoid misunderstanding.

To get the best time of each item into one row:

besttime = [value['BEST']['TIME'] for value in data.values()]



For all scenarios:
scenarios = next(iter(data.values())).keys()
time = [[value[scenario]['TIME'] for value in data.values()] for scenario in scenarios]
writer.writerows(time)



For example (Python 3.x):

data = {'bubble_sort':{'BEST':{'COMP':1, 'PERM':2, 'TIME':3},
                       'RND':{'COMP':4, 'PERM':5, 'TIME':6},
                       'WORST':{'COMP':7, 'PERM':8, 'TIME':9}},
        'hoare_sort':{'BEST':{'COMP':10, 'PERM':11, 'TIME':12},
                      'RND':{'COMP':13, 'PERM':14, 'TIME':15},
                      'WORST':{'COMP':16, 'PERM':17, 'TIME':18}}}
scenarios = next(iter(data.values())).keys()
time = [[value[scenario]['TIME'] for value in data.values()] for scenario in scenarios]
with open(r'D:/data.csv', 'w') as f:
    writer = csv.writer(f)
    writer.writerows(time)


The results:


           (bubble_sort)        (hoarse_sort)
(best)      3                   12
(rnd)       6                   15
(worst)     9                   18

Ollisteka Posted - 09/14/2017 : 03:43:18 AM
quote:


Please be more specific about the relationship between the table and the Python dictionary.

None of the values in the table is from the dictionary provided.

For example,

1) Elements' number [100,200,300,400] is not from the Python dictionary provided.
2) Bubble Time [10, 15, 20, 30] is not from the Python dictionary provided.





Well, values in the table are absolutely random right now. But let's say that this data was collected on best case array of length 100. Then for 1st row there should be values from ['bubble_sort']['BEST']['TIME'], ['hoare_sort']['BEST']['TIME'] and so on. Then I'd make the same tables for worst case scenario (["WORST"]), random (["RND"]), and then repeat everything for number of comparissons (["COMP"]) and permutations done (["PERM"])
ZanHUNG Posted - 09/14/2017 : 02:34:27 AM
quote:
Originally posted by Ollisteka

Origin Ver. and Service Release (Select Help-->About Origin): 8.0724
Operating System: Windows 7

So, I have some data, which can fit in a table like tat one:



But what should I write in Python script, so when I import .csv file it would look like this exact table?

Right now I have this structure:

{'bubble_sort': {'BEST': {'COMP': 999000, 'PERM': 0, 'TIME': 1072.061538696289},
             'RND': {'COMP': 999000,
                     'PERM': 249853,
                     'TIME': 1731.0991287231445},
             'WORST': {'COMP': 999000,
                       'PERM': 499500,
                       'TIME': 2358.1347465515137}},
'hoare_sort': {'BEST': {'COMP': 10975, 'PERM': 0, 'TIME': 14.000654220581055},  #and so on


And this code to save it:

def write_csv_in_file(fn, data):
with open(fn + ".cvs", 'w') as file:
    writer = csv.writer(file)
    for key, value in data.items():
        writer.writerow([key, value])

And after importing get this table:

And it is far away from the variant I need.




Please be more specific about the relationship between the table and the Python dictionary.

None of the values in the table is from the dictionary provided.

For example,

1) Elements' number [100,200,300,400] is not from the Python dictionary provided.
2) Bubble Time [10, 15, 20, 30] is not from the Python dictionary provided.


The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000