remove a character from a data numpy array


remove a character from a data numpy array



I am currently importing a .txt file to a numpy array. The .txt file is organized by three columns with hundreds of thousands of rows.
Occasionally, for no apparent reason, the third column will have a attached to the number. This causes genfromtxt to import the number as nan. I have tried using a replace function for numpy, but I believe this function is looking for a string because I get an "EOL while scanning string literal" error code.enter image description here


numpy



genfromtxt


nan


numpy



Any advice?


import numpy as np
import numpy.core.defchararray as np_f

FLR = np.genfromtxt("C:UsersbrandDownloadsPythonMyFilesaupnipam_scan41_3DFLR.txt")
FLR = np_f(FLR, '', '')
x = FLR[:,][:,0]
y = FLR[:,][:,1]
z = FLR[:,][:,2]



I've added a picture of what the raw data looks like to show what I mean by it having a "" in the data



Following is the complete error code I get


File "<ipython-input-13-0876313d3bfc>", line 6
FLR = np_f(FLR, '', '')
^
SyntaxError: EOL while scanning string literal





This has nothing to do with numpy, you are missing a closing quote in this: FLR = np_f(FLR, '', '') line. You need to escape the , so try FLR = np_f(FLR, '', '')
– user3483203
Jun 29 at 17:53



FLR = np_f(FLR, '', '')


FLR = np_f(FLR, '', '')





Can you provide an example of data where this occurring so that the error can be reproduced?
– vealkind
Jun 29 at 17:53





If you're working with one and only one text file, it may just be easier to 'find and replace' in a text editor, removing the '' character. Not really a programming way to do it, but may be easier if it's just this one file.
– Sagasaki
Jun 29 at 17:53





@user3483203 I'm pretty sure that typo doesn't explain the issue described in the body of the question
– roganjosh
Jun 29 at 18:05





His error is ""EOL while scanning string literal"", pretty sure it's exactly what his issue is
– user3483203
Jun 29 at 18:05









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV