1

I have a text file which contains a log like this:

245     (click,view,view,check,view,view)         (22,1,5,6,7,15)

305     (view,run)       (5,6)

3051         (run,run)      (115,36)

It is tab seperated, the number of entries in the second column field is equal to the third column field.

I am finding it difficult to take this into python using np.loadtxt as it has a delimiter and text and brackets (circular) to separate the 2nd fields and 3rd fields.

Looking forward for suggestions on how I should go about it?

1 Answer 1

2

Perhaps it'd be best to parse it in some way with standard python first, before loading into numpy? Without knowing a lot about how numpy needs this to be formatted, below is an example to turn it into an array of arrays.

For instance you could use split().

Def MakeItAList(lineFromFile): list = split(lineFromFile, " ") list[1] = split(list[1][1:-1],",") list[2] = split(list[2][1:-1],",")

It's a bit clunky but it will turn 245 (click,view,view,check,view,view) (22,1,5,6,7,15). into something like [245, [click,view,view,check,view,view], [22,1,5,6,7,15]] which is a little more manageable as a data-structure.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.