The meaning of pandas

import pandas as pd
word = pd.read_table ("test.txt", encoding =" utf-8", names = ["query"])

what does the "query"" in the names here mean?

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.

in addition, I saw the headers here on the official website a little confused. The number in the "Row number (s) to use as the column names" line is regarded as the name of the column. How do you understand this?

Feb.28,2021

the best way is to give a small example to try,

suppose you have a comma-delimited data file of data.cvs , as follows

0     index,name,comment,,,,
1    1,name_01,coment_01,,,,
2    2,name_02,coment_02,,,,
3    3,name_03,coment_03,,,,
4    4,name_04,coment_04,,,,
5    5,name_05,coment_05,,,,

read

with the following code
import pandas as pd
word = pd.read_table('data.csv', delimiter=',',encoding = 'utf-8', names = ['index','name','comment','foo','bar','baz'], header=0)

print(word)

you will see the following results:

      index       name  comment  foo  bar  baz
1   name_01  coment_01      NaN  NaN  NaN  NaN
2   name_02  coment_02      NaN  NaN  NaN  NaN
3   name_03  coment_03      NaN  NaN  NaN  NaN
4   name_04  coment_04      NaN  NaN  NaN  NaN
5   name_05  coment_05      NaN  NaN  NaN  NaN
......

to answer your question: names refers to the column name of the data after reading memory, heads refers to the row number of the data table, and the real data starts after this row.

Menu