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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:26:38+00:00 2026-06-06T17:26:38+00:00

I made a list from a CSV file. It looks like this: [’18’, ’29’,

  • 0

I made a list from a CSV file. It looks like this:

['18', '29', '0'...'0', '-14', '9']

It had a text element in the beginning, which I popped. Now, Python doesn’t work with the list elements as with proper numbers. Whenever I try to parse the elements into floats, for example, I get the error message:

ValueError: could not convert string to float: -

My code looks like this:

list2=[[float(column) for column in row] for row in list1]

Or this:

list2 = [map(float, x) for x in list1]

Both versions produce the same result. If I try a different data type, I get messages like:

ValueError: invalid literal for int() with base 10: '-'

Can anyone tell me how do I get Python to parse the dash into a number correctly?

  • 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-06T17:26:41+00:00Added an answer on June 6, 2026 at 5:26 pm

    It looks like the list you’re creating is 1D but when you try and parse it you’re treating it as a 2D list which will try converting each character in each element to a float (hence it throws an error while trying to do float('-')). Try replacing the line with the following to fix the problem:

    list2 = map(float, list1)
    

    You should also try adding print list1 before that line to confirm that the list has the structure you think it has.

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

Sidebar

Related Questions

I'd like to get a word list from a text file using Ruby. I
I have a datagrid in a WPF populated from a csv file. This is
I have csv file like this: item,#RGB item1,#ffcc00 item1,#ffcc00 item1,#ff00cc item2,#00ffcc item2,#ffcc00 item2,#ffcc00 item2,#ffcc00
I made a query that retrieve a list of items from a database: CREATE
I have made a list with few elements in it. Now everything looks right,
The html of this script is made with list items http://www.jeremymartin.name/projects.php?project=kwicks Where can I
I would like to re-render a list made using Marionette.ItemView when the corresponding model
I just run into another problem with my To-do-like sortable list made with Knockout
I have a Task list in Sharepoint 2007 SP2. For this list I made
I have a CSV file. Each line is made up of the same format

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.