Ref: <https://stackoverflow.com/a/19726081/1182021>

```
OrderedDict([
('company 1', tup(price=246, year='1991', month='march')),
('company 2', tup(price=245, year='1990', month='jan')),
('company 3', tup(price=243, year='1990', month='jan')),
('company 4', tup(price=247, year='1991', month='december')),
('company 5', tup(price=245, year='1991', month='june'))])

```

How to export this data in csv format like this:

```
Company Name , Price , Year , Month
Company 1    , 246   , 1991 , march
Company 2    , 245   , 1990 , jan

```

I tried creating a csv using `import csv` like this (**ALL IN SAME ROW**):

```
myfile = open(csvfile, 'wb')
wr = csv.writer(myfile , quoting=csv.QUOTE_ALL)
wr.writerow(data_list)

```

**EDIT 1**

where `data_list` is the OrderedDict and I am getting all data incorrect format

```
Company-A | Filtered(Year='2013', Month='Dec', Price=0) Company-B   | Filtered(Year='2013', Month='Dec', Price=0) |     Company-C  |    Filtered(Year='2013', Month='Dec', Price=0) |   Company-D |     Filtered(Year='2013', Month='Dec', Price=0) Company-E |     Filtered(Year='2013', Month='Dec', Price=0)

```

**EDIT 2**

OK I converted OrderedDict to simple list by `data_list = OrderedDict.items()`

And as suggested by [mkrehili](https://stackoverflow.com/a/24839761/1182021) I have this as my export method:

```
def ExportData(csv_file, data_list):
    csv_file = open(csv_file, 'wb')
    wr = csv.writer(csv_file, quoting=csv.QUOTE_ALL)

    for company_name, company_data in data_list:
        wr.writerow([company_name] + list(company_data))

```

And I am getting this list now:

```
[('Company-A', Filtered(Year='2013', Month='Dec', Price=0)), ('Company-B', Filtered(Year='2013', Month='Dec', Price=0)), ('Company-C', Filtered(Year='2013', Month='Dec', Price=0)), ('Company-D', Filtered(Year='2013', Month='Dec', Price=0)), ('Company-E', Filtered(Year='2013', Month='Dec', Price=0))]

```

But when I am converting it in CSV the following is the output:

```
Company-A   2013    Dec 0
Company-B   2013    Dec 0
Company-C   2013    Dec 0
Company-D   2013    Dec 0
Company-E   2013    Dec 0

```

**EDIT 3**
Actually both the data are not coming same:

In OrderedDict its:

```
OrderedDict([
('company A', tup(price=246, year='1991', month='march')),
('company B', tup(price=245, year='1990', month='jan')),
('company C', tup(price=243, year='1990', month='jan')),
('company D', tup(price=247, year='1991', month='december')),
('company E', tup(price=245, year='1991', month='june'))])

```

But once I do `data_list = OrderedDict.items()` it gives me this data: Which is not in correct format:

```
[('Company-A', tup(price=0, year="2013", month='Dec')),
 ('Company-B', tup(price=0, year="2013", month='Dec')), 
 ('Company-C', tup(price=0, year="2013", month='Dec')), 
 ('Company-D', tup(price=0, year="2013", month='Dec')), 
 ('Company-E', tup(price=0, year="2013", month='Dec'))]

```

So majorly my issue is to create a simple list where i have list like this:

```
Company Name , Price , Year , Month
Company A    , 246   , 1991 , march
Company B    , 245   , 1990 , jan
......
......

```

**EDIT 4**

```
with open(csv_file, 'w') as f:
    w = csv.writer(f)
    w.writerow(('Company Name', 'Year', 'Month', 'Price'))
    w.writerows([(name, data.year, data.month, data.price) for   name, data in data_list])`

```

This is giving me right export, but after each line I am having an empty row, like this:

```
Company Name    Year    Month   Price

Company-A   2000    Mar 1000

Company-B   2007    Mar 986

Company-C   1993    Jun 995

Company-D   2002    Apr 999

Company-E   2008    Oct 997

```