0

I have a .csv file, which I can read in Pandas. The .csv file looks like the following.

a b c d e
1 4 3 2 5
6 7 8 3 6
...

What I need to achieve is, that I can extract a and b as a column vector and [c d e] as a matrix. I used Pandas with the following code to read the .csv file:

pd.read_csv('data.csv', sep=',',header=None)

But this will give me a vector like this: [[a,b,c,d,e],[1,4,3,2,5],...]

How can I extract the columns? I heared about df.iloc, but this cannot be used here, since after pd.read_csv there is only one column.

1 Answer 1

2

You should be able to do that with:

ds = pd.read_csv('data.csv', sep=',',header=0)
column_a = ds["a"]
matrix = ds[["c","d","e"]]
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.