如何使用Pandas在python的CSV文件中显示列?

2024-05-21 00:48:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下CSV文件:

enter image description here

我的目标是显示以下列:日期、入站和出站。为此,我使用pandas来获得我想要的

我的代码如下:

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

我有个错误:

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

Tags: columns文件csvpath代码目标pandasinput
1条回答
网友
1楼 · 发布于 2024-05-21 00:48:35

似乎您需要跳过第一行:

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

或为新标题指定行,例如10th行:

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

相关问题 更多 >