Tim Luka
Tim Luka

Reputation: 481

How to display columns in CSV file in python using Pandas?

I have the following CSV file:

enter image description here

I aim to show just the following columns: Date, Inbound and Outbound. For that, I'm using pandas to get what I want.

My code is the following:

path_input = 'CSR1 - Traffic - 10.10.1.1 (Tunnel0).csv'
data = pd.read_csv(path_input,sep='\t')
data.columns = ["Date", "Inbound", "Outbound"]

I'm having this error:

----> 3 data.columns = ["Date", "Inbound", "Outbound"]
ValueError: Length mismatch: Expected axis has 1 elements, new values have 3 elements

Upvotes: 1

Views: 145

Answers (1)

jezrael
jezrael

Reputation: 863156

It seems you need skip first rows:

data = pd.read_csv(path_input,sep='\t', skiprows=9)

Or specify row for new header, e.g. 10th row:

data = pd.read_csv(path_input,sep='\t', header=[10])

Upvotes: 5

Related Questions