ZeeeeeV
ZeeeeeV

Reputation: 381

Python Spliting extracted CSV Data

I have some data (taken from a CSV file) in the format:

 MyValues = [[2 2 2 1 1]
             [2 2 2 2 1]
             [1 2 2 1 1]
             [2 1 2 1 2]
             [2 1 2 1 2]
             [2 1 2 1 2]
             [2 1 2 1 2]
             [2 2 2 1 1]
             [1 2 2 1 1]]

I would like to split this data into 2/3 and 1/3 and be able to distinguish between them. For example

twoThirds = [[2 2 2 1 1]
             [2 2 2 2 1]
             [1 2 2 1 1]
             [2 1 2 1 2]
             [2 1 2 1 2]
             [2 1 2 1 2]]

 oneThird = [[2 1 2 1 2]
             [2 2 2 1 1]
             [1 2 2 1 1]]

I have tried to use the following code to achieve this, but am unsure if i have gone about this the correct way?

   twoThirds = (MyValues * 2) / 3 #What does this code provide me?

Upvotes: 0

Views: 112

Answers (1)

root
root

Reputation: 80426

It's just a list, use the slice notation. And read the docs:

In [59]: l = range(9)

In [60]: l[:len(l)/3*2]
Out[60]: [0, 1, 2, 3, 4, 5]

In [61]: l[len(l)/3*2:]
Out[61]: [6, 7, 8]

Upvotes: 2

Related Questions