0

I have data in csv file without header. I need to parse some columns.

A part of data:

-1.0,-0.0246259814315,1174.60023796
 1.0,-0.978057706084,1083.19880269
-1.0,0.314271994507,-1472.97760911
-1.0,0.179751565771,231.017267343
1.0,-1.26254374278,-778.271726463
-1.0,0.249969939456,-52.8014826538
1.0,-1.87039747875,-324.235348241

I need to load only second and third columns. I use train_X = pd.read_csv("perceptron-train.csv", sep=',', parse_dates=[1], usecols=[2, 3]) but it returns IndexError: list index out of range

10
  • 1
    you need to enclose square brackets: train_X = pd.read_csv("perception-train.csv", parse_dates=[1]) also for usecols you should pass a list of either the names or ordinal positions of the columns Commented Aug 5, 2016 at 13:22
  • 1
    Use parse_dates=[1] and keep in mind that the column-indices are zero-based. Commented Aug 5, 2016 at 13:23
  • @EdChum if I want to scecify two columns I should use two brakets? Commented Aug 5, 2016 at 13:26
  • @ldevyataykina no this is a list. You separate them by a comma Commented Aug 5, 2016 at 13:26
  • 2
    Please can you edit your question with raw data, your code and the desired output, I and others have repeatedly asked you to do this for the majority of your questions, also the data you posted doesn't look like a datetime string so I don't see what you're trying to do here Commented Aug 5, 2016 at 13:41

1 Answer 1

1

IIUC indices are zero-based so you need:

train_X = pd.read_csv("perceptron-train.csv", sep=',', parse_dates=[1], usecols=[1, 2])

Also I don't know if this also means you need to change your date col:

train_X = pd.read_csv("perceptron-train.csv", sep=',', parse_dates=[0], usecols=[1, 2])

However, looking at your data I don't understand how to interpret the first or second column as a datetime as they look weird

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.