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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 Make the same table using Python cvs module
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Ollisteka

Russia
2 Posts

Posted - 09/14/2017 :  12:54:49 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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.

Edited by - Ollisteka on 09/14/2017 01:08:22 AM

ZanHUNG

20 Posts

Posted - 09/14/2017 :  02:34:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.

Go to Top of Page

Ollisteka

Russia
2 Posts

Posted - 09/14/2017 :  03:43:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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"])
Go to Top of Page

ZanHUNG

20 Posts

Posted - 09/14/2017 :  05:01:05 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000