pythonnumpygenfromtxt

deletechars parameter in genfromtxt not working as expected


I am working with some csv that have single quotes surrounding the values of the first column. I need to remove them in order to do further comparisons against other stuff. So I really need to perform this replacement efficiently.

I am using genfromtxt with deletechars="'" but single quotes are kept anyway.

A sample code is here

import numpy as np
file_name='myCSV.csv'
np.genfromtxt(file_name,delimiter=',',usecols=0,dtype='S30',skip_header=1,deletechars="'")

What I have : 'myValue'

What I want : myValue

What I get : 'myValue' the same as not using deletechars

EDIT

converters={0:lambda x: x.replace('\'','')} 

solves my problem but why deletechars does not work remains a mystery


Solution

  • deletechars : str, optional
        A string combining invalid characters that must be deleted from the
        names.
    

    It deletes these chars from the NAMES - field or column names, not the row values. Note that a number of other parameters also deal with the names.