elly
elly

Reputation: 166

Python: Manipulate an array

I have an array that looks just like this one:

 array(['00:00;1;5950;6\r', '00:10;1;2115;6\r', '00:10;2;4130;6\r',
   '00:10;3;5675;6\r', '00:20;1;1785;6\r'], 
  dtype='|S15')

For my evaluation I need only the value after the second semicolon at each array entry. Here in this example, I need the values:

5950, 2115, 4130, 5675, 1785.

Is it possible to manipulate the array in way to get the entries I want? And how can that be solved? I know how to remove the symbols, so in the end I get the array:

['0000159506\r', '0010121156\r', '0010241306\r', '0010356756\r', '0020117856\r']

But I don't know if this is the right way to handle these problem. Do anyone know what to do? Thank you very much!

Upvotes: 1

Views: 87

Answers (2)

farhawa
farhawa

Reputation: 10398

Try this:

A = array(['00:00;1;5950;6\r', '00:10;1;2115;6\r', '00:10;2;4130;6\r',
   '00:10;3;5675;6\r', '00:20;1;1785;6\r'], 
  dtype='|S15')
list_ = [str(x.split(";")[2]) for x in A]

Upvotes: 2

NendoTaka
NendoTaka

Reputation: 1224

The best way to get these values is to use the python split function.

You can choose the delimiter. So in this case the delimiter can be a ;.

result = line.split(';')

and then just find the third value of the resulting list.

num = result[2]

Upvotes: 1

Related Questions