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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:32:42+00:00 2026-06-13T00:32:42+00:00

When I try to read a space separated file using genfromtxt and using a

  • 0

When I try to read a space separated file using genfromtxt and using a converter function to convert numbers with a comma as decimal separator, I get a type error. It seems there is something wrong with my converter function. However, when I use it on a single value, it does work properly.

This is my code (I’m using Matplotlib/Pylab):

t = dtype([('Date', 'U12'), ('Time', 'U10'), ('Cond', 'f4'), ('Temp', 'f4')])

conv = lambda valstr: float(valstr.replace(',','.'))

c = {2:conv, 3:conv}

data = genfromtxt('Example.csv', dtype = t,
    skip_header=1, delimiter = ' ', converters = c)

The data looks like this:

Date Time Cond Temp
11-10-2012 00:00:14 5,430583 29,5107
11-10-2012 00:00:15 5,431812 29,45066
11-10-2012 00:00:16 5,435501 29,43862
11-10-2012 00:00:17 5,436732 29,43862
...

And this is part of the error message:


TypeError                                 Traceback (most recent call last)
<ipython-input-41-c65c2d17c55d> in <module>()
      5 c = {2:conv, 3:conv}
      6 
----> 7 data = genfromtxt('Example.csv', dtype = t, skip_header=1, delimiter = ' ', converters = c)


...


<ipython-input-41-c65c2d17c55d> in <lambda>(valstr)
      1 t = dtype([('Date', 'U12'), ('Time', 'U10'), ('Cond', 'f4'), ('Temp', 'f4')])
      2 
----> 3 conv = lambda valstr: float(valstr.replace(',','.'))
      4 
      5 c = {2:conv, 3:conv}

TypeError: expected an object with the buffer interface

Am I doing something wrong here, or is this some kind of bug in genfromtxt?

I’am using Python 3.2 on Win7 x64. Numpy version is 1.6.2.

  • 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-13T00:32:43+00:00Added an answer on June 13, 2026 at 12:32 am

    Apparently, genfromtxt feeds read columns to converter functions as byte strings, not as unicode strings.

    The problem was solved for me by changing the code of the converter function as follows:

    conv = lambda valstr: float(valstr.decode("utf-8").replace(',','.'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to read file /proc/'pid'/status, using c program. The code is as follows,
When I try to read bash history into vim, I get nothing. :r !history
I get a warning in MSVC++ when I try to read an integer from
I'm writing on c++ in VS2010 Windows 7. I try to read file of
i get an Access Violation if i try to change the ribbon style using
I want to get the content in a text file and I am using
I am using XSSF of apache-POI to read the XLSX file. I was getting
I try to read a csv file. my fifth record contans a date: 03/11/2008
I try to get rounded corners on a UIImage, what I read so far,
i try to read Data from an Oracle-Database. The problem is that in some

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.