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

  • Home
  • SEARCH
  • 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 9081267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:16:28+00:00 2026-06-16T20:16:28+00:00

Possible Duplicate: Creating a dictionary from a CSV file I am having an issue

  • 0

Possible Duplicate:
Creating a dictionary from a CSV file

I am having an issue when trying to print a dictionary to a CSV file. The dictionary currently has 4 columns but all 4 columns are printed in 1 single column. It may be the for loop that I am using to write to the CSV file is to blame but I am not quite sure. I am trying to have the dictionary print in each column.

Sample Data:

     Date        First Name     Last Name     Score
12/28/2012 15:15        John          Smith        20
12/29/2012 15:15        Alex          Jones        38
12/30/2012 15:15      Michael       Carpenter      25

Below are some code excerpts:

import csv

csvWriter = csv.writer(open("C:\\Users\\Chris\\Desktop\\test_out.csv", 'w'), delimiter=' ', quotechar=' ', quoting=csv.QUOTE_MINIMAL)

For loop to read in CSV file above:

for row in reader:

for k, v in row.items():

    if not k in mydict:
        mydict[k] = [v]
    else:
        mydict[k].append(v)

For loop to print Dictionary keys to CSV file.

for item in mydict.keys():
    csvWriter.writerow(item)

Current output (column headings):

D a t e

F i r s t    N a m e

L a s t      N a m e

S c o r e

Wanted output (column headings):

Date      First Name       Last Name       Score

Any help would be greatly appreciated.

  • 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-16T20:16:29+00:00Added an answer on June 16, 2026 at 8:16 pm

    Now that I understand your structure better, try this:

    #first write column headers
    csvWriter.writerow(list(mydict.keys())
    
    #now data, assuming each column has the same # of values
    for i in xrange(len(mydict['Date'])):
        csvWriter.writerow([mydict[k][i] for k in mydict.keys()])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Creating or assigning variables from a dictionary in Python Hello we have
Possible Duplicate: Creating, opening and printing a word file from C++ Hi, I need
Possible Duplicate: Efficient Method for Creating CSV String from Lists/SortedLists C#? Here i need
Possible Duplicate: T-SQL Pivot? Possibility of creating table columns from row values I've been
Possible Duplicate: What is the 'new' keyword in JavaScript? creating objects from JS closure:
Possible Duplicate: Creating makefile Hello, I am trying to create the makefiles and configure
Possible Duplicate: python: creating excel workbook and dumping csv files as worksheets How would
Possible Duplicate: Load local HTML file in a C# WebBrowser I´m creating program in
Possible Duplicate: Scanner issue when using nextLine after nextInt I am creating a client
Possible Duplicate: Creating a simple XML file using python I want to write a

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.