使用第一行作为数据框中的标题

时间:2014-07-24 11:29:55

标签: python pandas

u_cols = ["Inv. Date","Customer Name","Model","Variant"]
users=pd.read_csv('5ch.xls.Sheet1.cvs', sep=',', names=u_cols)

有时我不知道列标题列表。有没有办法告诉数据框使用第一行作为名称?

1 个答案:

答案 0 :(得分:2)

默认情况下这样做。 header read_csv参数默认为0(给定CSV文件的第一行),除非您传递了names参数。

在你的情况下,我不明白为什么你不能简单地写

users=pd.read_csv('5ch.xls.Sheet1.cvs')

鉴于sep默认为逗号。