Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8002969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:31:45+00:00 2026-06-04T16:31:45+00:00

I had items that scraped from a site which i placed them in to

  • 0

I had items that scraped from a site which i placed them in to json files like below

{
 "author": ["TIM ROCK"], 
 "book_name": ["Truk Lagoon, Pohnpei & Kosrae Dive Guide"], 
 "category": "Travel", 
}
{
 "author": ["JOY"], 
 "book_name": ["PARSER"], 
 "category": "Accomp", 
}

I want to store them in csv file with one dictionary per one row in which one item per one column as below

|    author   |     book_name     |    category   |
|   TIM ROCK  |  Truk Lagoon ...  |     Travel    |
|     JOY     |   PARSER          |     Accomp    |

i am getting the items of one dictionary in one row but with all the columns combined

My pipeline.py code is

import csv

class Blurb2Pipeline(object):

    def __init__(self):
        self.brandCategoryCsv = csv.writer(open('blurb.csv', 'wb'))
        self.brandCategoryCsv.writerow(['book_name', 'author','category'])

    def process_item(self, item, spider):
        self.brandCategoryCsv.writerow([item['book_name'].encode('utf-8'),
                                    item['author'].encode('utf-8'),
                                    item['category'].encode('utf-8'),
                                     ])
        return item        
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:31:46+00:00Added an answer on June 4, 2026 at 4:31 pm

    The gist is this is very simple with csv.DictWriter:

    >>> inputs = [{
    ...  "author": ["TIM ROCK"], 
    ...  "book_name": ["Truk Lagoon, Pohnpei & Kosrae Dive Guide"], 
    ...  "category": "Travel", 
    ... },
    ... {
    ...  "author": ["JOY"], 
    ...  "book_name": ["PARSER"], 
    ...  "category": "Accomp", 
    ... }
    ... ]
    >>> 
    >>> from csv import DictWriter
    >>> from cStringIO import StringIO
    >>> 
    >>> buf=StringIO()
    >>> c=DictWriter(buf, fieldnames=['author', 'book_name', 'category'])
    >>> c.writeheader()
    >>> c.writerows(inputs)
    >>> print buf.getvalue()
    author,book_name,category
    ['TIM ROCK'],"['Truk Lagoon, Pohnpei & Kosrae Dive Guide']",Travel
    ['JOY'],['PARSER'],Accomp
    

    It would be better to join those arrays on something, but since elements can be a list or a string, it’s a bit tricky. Telling if something is a string or some-other-iterable is one of the few cases in Python where direct type-checking makes good sense.

    >>> for row in inputs:
    ...     for k, v in row.iteritems():
    ...         if not isinstance(v, basestring):
    ...             try:
    ...                 row[k] = ', '.join(v)
    ...             except TypeError:
    ...                 pass
    ...     c.writerow(row)
    ... 
    >>> print buf.getvalue()
    author,book_name,category
    TIM ROCK,"Truk Lagoon, Pohnpei & Kosrae Dive Guide",Travel
    JOY,PARSER,Accomp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to Remove Badge from the tabbar item i had use below code but
Say, for example purposes I wanted a list of items that each had a
The invoice input values which hold the totals of invoice line items that get
I have a list of 6500 items that I would like to trade or
So I want a list of items that when you select them they expand
I am developing a website with nav items that cover the whole stage from
Let's say we have a table for items that looks like this item_id item_visits
I used to use Doxygen, which produced a nice report listing items that were
I have two list items that, when clicked, should change classes from '.off' to
I had thought about decorating various control items with attributes to declare group ownership,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.