Roman
Roman

Reputation: 131038

How to set columns while reading a data-frame from a csv file?

I try to read data from a CSV file using the following command:

df = pandas.read_csv(finp, header=None, columns = cols)

As a result I get the following error message:

TypeError: parser_f() got an unexpected keyword argument 'columns'

I resolve the problem in the following way:

df = pandas.read_csv(finp, header=None)
df.columns = cols

But I still wonder why it did not worked the first way. Any ideas?

Upvotes: 2

Views: 8484

Answers (1)

knagaev
knagaev

Reputation: 2957

There is no parameter 'columns'. Use 'names' instead of it.

By the way, do you have a header rows in your CSV?

Upvotes: 8

Related Questions