import pandas as pd
word = pd.read_table('test.txt', encoding = 'utf-8', names = ['query'])
这里的names 里的 ‘query’是什么意思??
header : int, list of ints, default ‘infer’
Row number(s) to use as the column names, and the start of the data. Defaults to 0 if no names passed, otherwise None. Explicitly pass header=0 to be able to replace existing names. The header can be a list of integers that specify row locations for a multi-index on the columns E.g. [0,1,3]. Intervening rows that are not specified will be skipped (e.g. 2 in this example are skipped). Note that this parameter ignores commented lines and empty lines if skip_blank_lines=True, so header=0 denotes the first line of data rather than the first line of the file.
另外我在官网看到这里的headers 有点迷惑 ,“Row number(s) to use as the column names ” 行的数字当成列的名字 ,这怎么理解呢?
最好的办法是来个小例子试一下,
假设你有一个
data.cvs
的逗号分隔的数据文件,内容如下用下面的代码来读
你将看到如下的结果:
回答你的问题:names是指读到内存后的数据的列名,heads是指数据表头行号,真正的数据是这一行之后开始。