2021年3月13日星期六

Python: remove single quotes around array

I have data that looks like this: minterms = [['1,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x'], ['x,x,x,x,1,x,x,x,x,x,x,x,x,x,x,x,1,x,x,x,x,x,x']]

and I want to remove the single quotes around each array to get this:

minterms = [[1,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x], [x,x,x,x,1,x,x,x,x,x,x,x,x,x,x,x,1,x,x,x,x,x,x]]

I have tried

mintermNew = minterms.replace("'", "")  

and this doesn't work. What am I doing wrong here?

Edit: Here is a snippet of my code giving a bit more context.

dontcares = []  mintermAry = []  for mindata in minterms:      for mindataIdx in mindata:          mintermAry.append(mindataIdx.split())      print(SOPform(fullsymlst, mintermAry, dontcares))    return  

I am using mindataIdx.split() to put the data into an array. MindataIdx is the data that looks like [['1,x,x,x,x....']. Using .split("") as mentioned in the commends throws this error: mintermAry.append(mindataIdx.split("")) ValueError: empty separator

using .split(" ") yields no changes.

Edit 2:

The data is being read into a dataframe from a file. The first 4 rows I want to discard. I am using this method to do it.

df = df.replace('-', 'x', regex=True)  dfstr =   df.to_string(header=False,index=False,index_names=False).split('\n')  dfArray = np.array(dfstr)  dfArrayDel = np.delete(dfArray,range(4), 0)  dfArrayData = np.char.lstrip(dfArrayDel)  splitData = np.char.split(dfArrayData)  
https://stackoverflow.com/questions/66619268/python-remove-single-quotes-around-array March 14, 2021 at 06:38AM

没有评论:

发表评论