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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:52:37+00:00 2026-06-04T12:52:37+00:00

I have a csv dump that I’m trying to import to run analysis on

  • 0

I have a csv dump that I’m trying to import to run analysis on metrics therein, cherry picking certain metrics to look at. Some of the cells are strings and some are numbers. However, I can’t get csv.reader to handle the numbers properly. A snippet:

with open('t0.csv', 'rU') as file:
    reader = csv.reader(file, delimiter=",", quotechar='|')
    reader.next() # Burn header row
    for row in reader:
        if row[0] != "": # Burn footer row
            t0_company.extend([unicode(row[3], 'utf-8')])
            t0_revenue.extend([row[9]])
            t0_clicks.extend([row[10]])
            t0_pageviews.extend([row[11]])
            t0_avg_cpc.extend([row[13]])
            t0_monthly_budget.extend([row[16]])

I input another file of the same format for metrics at t1. Then I create two dicts for each metric (one at t0 and the other at t1) with the form metric_dict = {‘company’: ‘metric’} like this:

metric = dict(zip(company, metric))

Running simple math on these metrics is problematic however:

percent_change = float(t1_metric_dict[company]) / float(t0_metric_dict[company]) - 1

Returns errors like:

Traceback (most recent call last):
File "report.py", line 104, in <module>
start_revenue_dict[company], end_revenue_dict[company], float(end_revenue_dict[company]) / float(start_revenue_dict[company]) - 1,
ValueError: could not convert string to float: "6.18"

It seems to pick the same number to complain about every time.

I’m fairly certain the error happens in the division as everything works normally if I swap in a placeholder string as the third element.

I also tried using quoting=csv.QUOTE_NONNUMERIC, changing the second line in the first snippet to

reader = csv.reader(file, delimiter=",", quotechar='|', quoting=csv.QUOTE_NONNUMERIC)

Which gets me this error:

Traceback (most recent call last):
File "report.py", line 30, in <module>
reader.next()
ValueError: could not convert string to float: "Type"

I’ve tried making sure the csv doesn’t have any weird cell types (everything is text) even though I doubt it matters. I’d appreciate any help on this one.

—— Update ——

One of the columns in my input file contains email addresses. As an experiment, I removed all @s from the input docs which changed the error message I’m getting to:

Traceback (most recent call last):
File "report.py", line 129, in <module>
unicode_row = [str(item).encode('utf8') for item in utf8_row]
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 2: ordinal not in range(128)

The code it’s referencing is the csv out section:

writer = csv.writer(open('output.csv', 'wb'), delimiter=",", quotechar='|')
for utf8_row in report:
    unicode_row = [str(item).encode('utf8') for item in utf8_row]
    writer.writerow(unicode_row)

—– Update #2 —–

As requested, here is the full snippet that’s causing problems:

for company in companies_in_both:
report.append([company,
      start_revenue_dict[company], end_revenue_dict[company], float(end_revenue_dict[company]) / float(start_revenue_dict[company]) - 1,
      start_clicks_dict[company], end_clicks_dict[company], float(end_clicks_dict[company]) / float(start_clicks_dict[company]) - 1,
      start_pageviews_dict[company], end_pageviews_dict[company], float(end_pageviews_dict[company]) / float(start_pageviews_dict[company]) - 1,
      start_avg_cpc_dict[company], end_avg_cpc_dict[company], float(end_avg_cpc_dict[company]) / float(start_avg_cpc_dict[company]) - 1,
      start_monthly_budget_dict[company], end_monthly_budget_dict[company], float(end_monthly_budget_dict[company]) / float(start_monthly_budget_dict[company]) - 1])
  • 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-04T12:52:38+00:00Added an answer on June 4, 2026 at 12:52 pm

    Are you sure '|' is the right thing to be using for quotechar? I see you have numerous CSV questions, and all your examples use that, so maybe it really is what you want. But it’s astoundingly unusual.

    Your ValueError message is telling you that you have double-quotes in your data. That is, instead of doing the equivalent of float("6.18"), Python is trying to do float('"6.18"'), and it’s choking.

    It may be helpful to give a few complete lines of your actual CSV data, surrounding where the error occurs, as viewed with Notepad or equivalent (provided it’s not confidential, legally sensitive, etc.).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV dump from another DB that looks like this (id, name,
I have CSV files that have multiple columns that are sorted. For instance, I
I have .csv file that contain 2 columns delimited with , . file.csv word1,word2
How to read and import .csv file in groovy on grails. I have .csv
I'm running an import script which imports a CSV dump of a database into
Here's what I'm trying to accomplish. I need to have a single CSV with
I have a csv file with dump data of table and I would like
I have a simple script that accepts a CSV file and reads every row
I am trying to import a large csv file into MySQL. It's about 1.4
I have the below script to import data from a csv file on my

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.