Search code examples
pythonlistods

How to make list from .ods file?


I want to make a 2-D list from .ods file after reading this file. From following code I have gotten following output.

from pyexcel_ods import get_data
data = get_data("demo.ods")

Output:

In [2]: data
Out[2]: 
OrderedDict([('Sheet1',
              [['ID',
                'Start_1',
                'End_1',
                'Start_2',
                'End_2',
                'Start_3',
                'End_3'],
               [1007, 59, 93, 160, 194, 424, 459],
               [1011, 436, 460, 154, 180, 500, 527],
               [1025, 459, 501, 304, 334, 3, 32]])])

But I want output like my_2d_list.

my_2d_list = [[1007, 59, 93, 160, 194, 424, 459],
               [1011, 436, 460, 154, 180, 500, 527],
               [1025, 459, 501, 304, 334, 3, 32]] 

How can I do this?


Solution

  • It looks like you want to remove the "sheet name" and "column header"

    # You can add below code:
    
    od = OrderedDict([('Sheet1',
                  [['ID',
                    'Start_1',
                    'End_1',
                    'Start_2',
                    'End_2',
                    'Start_3',
                    'End_3'],
                   [1007, 59, 93, 160, 194, 424, 459],
                   [1011, 436, 460, 154, 180, 500, 527],
                   [1025, 459, 501, 304, 334, 3, 32]])])
    
    my_2d_list = list(od.values())[0][1:]
    

    I hope this helps!