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 8375383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:09:42+00:00 2026-06-09T15:09:42+00:00

Using some help from the internet, I construct a generic function that extracts specific

  • 0

Using some help from the internet, I construct a generic function that extracts specific columns from a csv file and reads it to a dictionary, specified by the input keys.

import csv
def dict_filter(it, keys):
    for d in it:
        yield dict((k, d[k]) for k in keys)

Then I call this method later to write these columns into another CSV file using DictReaderand DictWriter:

fieldnames = ["_STATE", "HEIGHT", "WEIGHT", "_BMI", "AGE", "CTYCODE", "IYEAR"]
source = open("data88.csv", 'r')
reader = csv.DictReader(source) 
result = open("aggregate_data.csv", 'w') 
writer = csv.DictWriter(result, fieldnames, extrasaction='ignore') 
for d in dict_filter(reader, fieldnames):
    if d['_STATE'] == "17" : 
         writer.writerow(str(d))

Here’s the error I get in terminal:

AttributeError: 'str' object has no attribute 'get' 

In TextWrangler:

Traceback (most recent call last): writer.writerow(str(d))

I’ve looked all over the internet and am not finding any relief. Why is writerow not working on my instance of DictWriter?

  • 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-09T15:09:44+00:00Added an answer on June 9, 2026 at 3:09 pm

    Change the line

    writer.writerow(str(d))
    

    to

    writer.writerow(d)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help on compiler flags in c++. I'm using a library that
I need some help using regex in java. Im trying to achieve 2 different
I need some help with overlaying views using the prism framework.Its a little more
I need some help extracting the following bits of information using regular expressions. Here
I'm using Firebird 2.1. I could use some help creating the following query or
Thanks for taking some time to help me out. Using: Microsoft Visual C# 2010
I am having some Internet Explorer 7 (and 8 beta) browser-specific problems with a
i really need some help on this. I searched the internet but couldn't find
I'm using the garb gem to pull some basic stats, like pageviews, from Google
I have the following situation: excel-like application, that is accessible from internet. 2 users

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.